mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-19 10:28:54 +00:00

git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@328908 c90b9560-bf6c-de11-be94-00142212c4b1
196 lines
5.6 KiB
XML
196 lines
5.6 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!-- $Revision$ -->
|
|
|
|
<refentry xml:id="evtimer.construct" xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink">
|
|
<refnamediv>
|
|
<refname>EvTimer::__construct</refname>
|
|
<refpurpose>Constructs an EvTimer watcher object</refpurpose>
|
|
</refnamediv>
|
|
|
|
<refsect1 role="description">
|
|
&reftitle.description;
|
|
<methodsynopsis>
|
|
<modifier>public</modifier> <methodname>EvTimer::__construct</methodname>
|
|
<methodparam><type>double</type><parameter>after</parameter></methodparam>
|
|
<methodparam><type>double</type><parameter>repeat</parameter></methodparam>
|
|
<methodparam><type>callable</type><parameter>callback</parameter></methodparam>
|
|
<methodparam
|
|
choice="opt"><type>mixed</type><parameter>data</parameter><initializer>&null;</initializer></methodparam>
|
|
<methodparam
|
|
choice="opt"><type>int</type><parameter>priority</parameter><initializer>0</initializer></methodparam>
|
|
</methodsynopsis>
|
|
<para>
|
|
Constructs an EvTimer watcher object.
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
<refsect1 role="parameters">
|
|
&reftitle.parameters;
|
|
<variablelist>
|
|
<varlistentry>
|
|
<term><parameter>after</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Configures the timer to trigger after <parameter>after</parameter> seconds.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>repeat</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
If repeat is <constant>0.0</constant>, then it will automatically be stopped once the timeout
|
|
is reached. If it is positive, then the timer will automatically be
|
|
configured to trigger again every repeat seconds later, until stopped
|
|
manually.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>callback</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
See <link linkend="ev.watcher-callbacks">Watcher callbacks</link>.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>data</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
Custom data associated with the watcher.
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
<varlistentry>
|
|
<term><parameter>priority</parameter></term>
|
|
<listitem>
|
|
<para>
|
|
<link linkend="ev.constants.watcher-pri">Watcher priority</link>
|
|
</para>
|
|
</listitem>
|
|
</varlistentry>
|
|
</variablelist>
|
|
</refsect1>
|
|
|
|
<refsect1 role="returnvalues">
|
|
&reftitle.returnvalues;
|
|
<para>
|
|
Returns EvTimer object on success.
|
|
</para>
|
|
</refsect1>
|
|
|
|
<refsect1 role="examples">
|
|
&reftitle.examples;
|
|
<example>
|
|
<title>Simple timers</title>
|
|
<programlisting role="php">
|
|
<![CDATA[
|
|
<?php
|
|
// Create and start timer firing after 2 seconds
|
|
$w1 = new EvTimer(2, 0, function () {
|
|
echo "2 seconds elapsed\n";
|
|
});
|
|
|
|
// Create and launch timer firing after 2 seconds repeating each second
|
|
// until we manually stop it
|
|
$w2 = new EvTimer(2, 1, function ($w) {
|
|
echo "is called every second, is launched after 2 seconds\n";
|
|
echo "iteration = ", Ev::iteration(), PHP_EOL;
|
|
|
|
// Stop the watcher after 5 iterations
|
|
Ev::iteration() == 5 and $w->stop();
|
|
// Stop the watcher if further calls cause more than 10 iterations
|
|
Ev::iteration() >= 10 and $w->stop();
|
|
});
|
|
|
|
// Create stopped timer. It will be inactive until we start it ourselves
|
|
$w_stopped = EvTimer::createStopped(10, 5, function($w) {
|
|
echo "Callback of a timer created as stopped\n";
|
|
|
|
// Stop the watcher after 2 iterations
|
|
Ev::iteration() >= 2 and $w->stop();
|
|
});
|
|
|
|
// Loop until Ev::stop() is called or all of watchers stop
|
|
Ev::run();
|
|
|
|
// Start and look if it works
|
|
$w_stopped->start();
|
|
echo "Run single iteration\n";
|
|
Ev::run(Ev::RUN_ONCE);
|
|
|
|
echo "Restart the second watcher and try to handle the same events, but don't block\n";
|
|
$w2->again();
|
|
Ev::run(Ev::RUN_NOWAIT);
|
|
|
|
$w = new EvTimer(10, 0, function() {});
|
|
echo "Running a blocking loop\n";
|
|
Ev::run();
|
|
echo "END\n";
|
|
?>
|
|
]]>
|
|
</programlisting>
|
|
&example.outputs.similar;
|
|
<screen>
|
|
<![CDATA[
|
|
2 seconds elapsed
|
|
is called every second, is launched after 2 seconds
|
|
iteration = 1
|
|
is called every second, is launched after 2 seconds
|
|
iteration = 2
|
|
is called every second, is launched after 2 seconds
|
|
iteration = 3
|
|
is called every second, is launched after 2 seconds
|
|
iteration = 4
|
|
is called every second, is launched after 2 seconds
|
|
iteration = 5
|
|
Run single iteration
|
|
Callback of a timer created as stopped
|
|
Restart the second watcher and try to handle the same events, but don't block
|
|
Running a blocking loop
|
|
is called every second, is launched after 2 seconds
|
|
iteration = 8
|
|
is called every second, is launched after 2 seconds
|
|
iteration = 9
|
|
is called every second, is launched after 2 seconds
|
|
iteration = 10
|
|
END
|
|
]]>
|
|
</screen>
|
|
</example>
|
|
</refsect1>
|
|
|
|
<refsect1 role="seealso">
|
|
&reftitle.seealso;
|
|
<simplelist>
|
|
<member><methodname>EvTimer::createStopped</methodname></member>
|
|
<member><classname>EvPeriodic</classname></member>
|
|
<member><link xlink:href="http://pod.tst.eu/http://cvs.schmorp.de/libev/ev.pod#code_ev_timer_code_relative_and_opti">ev_timer - relative and optionally repeating timeouts</link></member>
|
|
<member><link xlink:href="http://pod.tst.eu/http://cvs.schmorp.de/libev/ev.pod#Be_smart_about_timeouts">Be smart about timeouts</link></member>
|
|
</simplelist>
|
|
</refsect1>
|
|
|
|
</refentry>
|
|
|
|
<!-- Keep this comment at the end of the file
|
|
Local variables:
|
|
mode: sgml
|
|
sgml-omittag:t
|
|
sgml-shorttag:t
|
|
sgml-minimize-attributes:nil
|
|
sgml-always-quote-attributes:t
|
|
sgml-indent-step:1
|
|
sgml-indent-data:t
|
|
indent-tabs-mode:nil
|
|
sgml-parent-document:nil
|
|
sgml-default-dtd-file:"~/.phpdoc/manual.ced"
|
|
sgml-exposed-tags:nil
|
|
sgml-local-catalogs:nil
|
|
sgml-local-ecat-files:nil
|
|
End:
|
|
vim600: syn=xml fen fdm=syntax fdl=2 si
|
|
vim: et tw=78 syn=sgml
|
|
vi: ts=1 sw=1
|
|
-->
|