EvTimer::__constructConstructs an EvTimer watcher object
&reftitle.description;
publicEvTimer::__constructfloatafterfloatrepeatcallablecallbackmixeddata&null;intpriority0
Constructs an EvTimer watcher object.
&reftitle.parameters;
after
Configures the timer to trigger after
after
seconds.
repeat
If repeat is
0.0
, 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.
callback
See
Watcher callbacks
.
data
Custom data associated with the watcher.
priority
Watcher priority
&reftitle.returnvalues;
Returns EvTimer object on success.
&reftitle.examples;
Simple timers
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";
?>
]]>
&example.outputs.similar;
&reftitle.seealso;
EvTimer::createStoppedEvPeriodic
ev_timer - relative and optionally repeating timeouts
Be smart about timeouts