Fix method aliases in Event class (#687)

This also fixes the alias detection for the section order script
This commit is contained in:
George Peter Banyard 2022-03-13 18:11:31 +00:00 committed by GitHub
parent c55dde8f54
commit a916b9bd3d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 98 additions and 189 deletions

View file

@ -18,7 +18,7 @@
</methodsynopsis>
<para>
Marks event pending. Non-pending event will never occur, and the event
callback will never be called. In conjuction with
callback will never be called. In conjunction with
<methodname>Event::del</methodname>
an event could be re-scheduled by user at any time.
</para>
@ -32,6 +32,7 @@
has no effect.
</para>
</refsect1>
<refsect1 role="parameters">
&reftitle.parameters;
<variablelist>
@ -47,24 +48,99 @@
</varlistentry>
</variablelist>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para>
&return.success;
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<example>
<title>Adding a custom signal</title>
<programlisting role="php">
<![CDATA[
<?php
/*
Launch it in a terminal window:
$ php examples/signal.php
In another terminal window find out the pid and send SIGTERM, e.g.:
$ ps aux | grep examp
ruslan 3976 0.2 0.0 139896 11256 pts/1 S+ 10:25 0:00 php examples/signal.php
ruslan 3978 0.0 0.0 9572 864 pts/2 S+ 10:26 0:00 grep --color=auto examp
$ kill -TERM 3976
At the first terminal window you should catch the following:
Caught signal 15
*/
class MyEventSignal {
private $base, $ev;
public function __construct($base) {
$this->base = $base;
$this->ev = Event::signal($base, SIGTERM, array($this, 'eventSighandler'));
$this->ev->add();
}
public function eventSighandler($no, $c) {
echo "Caught signal $no\n";
$this->base->exit();
}
}
$base = new EventBase();
$c = new MyEventSignal($base);
$base->loop();
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
Caught signal 15
]]>
</screen>
</example>
<example>
<title>Adding a timer</title>
<programlisting role="php">
<![CDATA[
<?php
$base = new EventBase();
$n = 2;
$e = Event::timer($base, function($n) use (&$e) {
echo "$n seconds elapsed\n";
$e->delTimer();
}, $n);
$e->add($n);
$base->loop();
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
2 seconds elapsed
]]>
</screen>
</example>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<simplelist>
<member>
<methodname>Event::addSignal</methodname>
</member>
<member>
<methodname>Event::addTimer</methodname>
</member>
<member>
<methodname>Event::del</methodname>
</member>
<member><methodname>Event::add</methodname></member>
<member><methodname>Event::del</methodname></member>
<member><methodname>Event::signal</methodname></member>
<member><methodname>Event::timer</methodname></member>
</simplelist>
</refsect1>
</refentry>

View file

@ -3,96 +3,15 @@
<refentry xml:id="event.addsignal" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refnamediv>
<refname>Event::addSignal</refname>
<refpurpose>Makes signal event pending</refpurpose>
<refpurpose>&Alias; <methodname>Event::add</methodname></refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<modifier>public</modifier>
<type>bool</type>
<methodname>Event::addSignal</methodname>
<methodparam choice="opt">
<type>float</type>
<parameter>timeout</parameter>
</methodparam>
</methodsynopsis>
<para>
<methodname>Event::addSignal</methodname>
is an alias of
<methodname>Event::add</methodname>
&info.method.alias; <methodname>Event::add</methodname>
</para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<example>
<title>
<function>Event::addSignal</function> example</title>
<programlisting role="php">
<![CDATA[
<?php
/*
Launch it in a terminal window:
$ php examples/signal.php
In another terminal window find out the pid and send SIGTERM, e.g.:
$ ps aux | grep examp
ruslan 3976 0.2 0.0 139896 11256 pts/1 S+ 10:25 0:00 php examples/signal.php
ruslan 3978 0.0 0.0 9572 864 pts/2 S+ 10:26 0:00 grep --color=auto examp
$ kill -TERM 3976
At the first terminal window you should catch the following:
Caught signal 15
*/
class MyEventSignal {
private $base, $ev;
public function __construct($base) {
$this->base = $base;
$this->ev = Event::signal($base, SIGTERM, array($this, 'eventSighandler'));
$this->ev->addSignal();
}
public function eventSighandler($no, $c) {
echo "Caught signal $no\n";
$this->base->exit();
}
}
$base = new EventBase();
$c = new MyEventSignal($base);
$base->loop();
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
Caught signal 15
]]>
</screen>
</example>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<simplelist>
<member>
<methodname>Event::add</methodname>
</member>
<member>
<methodname>Event::del</methodname>
</member>
<member>
<methodname>Event::delSignal</methodname>
</member>
<member>
<methodname>Event::signal</methodname>
</member>
</simplelist>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:

View file

@ -3,70 +3,15 @@
<refentry xml:id="event.addtimer" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refnamediv>
<refname>Event::addTimer</refname>
<refpurpose>Makes timer event pending</refpurpose>
<refpurpose>&Alias; <methodname>Event::add</methodname></refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<modifier>public</modifier>
<type>bool</type>
<methodname>Event::addTimer</methodname>
<methodparam choice="opt">
<type>float</type>
<parameter>timeout</parameter>
</methodparam>
</methodsynopsis>
<para>
<methodname>Event::addTimer</methodname>
is an alias of
<methodname>Event::add</methodname>
&info.method.alias; <methodname>Event::add</methodname>
</para>
</refsect1>
<refsect1 role="returnvalues">
&reftitle.returnvalues;
<para></para>
</refsect1>
<refsect1 role="examples">
&reftitle.examples;
<example>
<title>
<function>Event::addTimer</function> example</title>
<programlisting role="php">
<![CDATA[
<?php
$base = new EventBase();
$n = 2;
$e = Event::timer($base, function($n) use (&$e) {
echo "$n seconds elapsed\n";
$e->delTimer();
}, $n);
$e->addTimer($n);
$base->loop();
?>
]]>
</programlisting>
&example.outputs.similar;
<screen>
<![CDATA[
2 seconds elapsed
]]>
</screen>
</example>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<simplelist>
<member>
<methodname>Event::add</methodname>
</member>
<member>
<methodname>Event::del</methodname>
</member>
<member>
<methodname>Event::delTimer</methodname>
</member>
</simplelist>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:

View file

@ -3,30 +3,15 @@
<refentry xml:id="event.delsignal" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refnamediv>
<refname>Event::delSignal</refname>
<refpurpose>Makes signal event non-pending</refpurpose>
<refpurpose>&Alias; <methodname>Event::del</methodname></refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<modifier>public</modifier>
<type>bool</type>
<methodname>Event::delSignal</methodname>
<void />
</methodsynopsis>
<para>
<methodname>Event::delSignal</methodname>
is an alias of
<methodname>Event::del</methodname>
&info.method.alias; <methodname>Event::del</methodname>
</para>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<simplelist>
<member>
<methodname>Event::del</methodname>
</member>
</simplelist>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:

View file

@ -3,31 +3,15 @@
<refentry xml:id="event.deltimer" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
<refnamediv>
<refname>Event::delTimer</refname>
<refpurpose>Makes timer event non-pending</refpurpose>
<refpurpose>&Alias; <methodname>Event::del</methodname></refpurpose>
</refnamediv>
<refsect1 role="description">
&reftitle.description;
<methodsynopsis>
<modifier>public</modifier>
<type>bool</type>
<methodname>Event::delTimer</methodname>
<void />
</methodsynopsis>
<para>
<methodname>Event::delTimer</methodname>
is an alias of
<methodname>Event::del</methodname>
.
&info.method.alias; <methodname>Event::del</methodname>
</para>
</refsect1>
<refsect1 role="seealso">
&reftitle.seealso;
<simplelist>
<member>
<methodname>Event::del</methodname>
</member>
</simplelist>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables: