Skip to content

Instantly share code, notes, and snippets.

@m4rw3r
Created January 22, 2012 15:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save m4rw3r/1657366 to your computer and use it in GitHub Desktop.
Save m4rw3r/1657366 to your computer and use it in GitHub Desktop.
<?php
$loop = EventLoop::getDefaultLoop();
function doSomething()
{
global $loop;
// Create a recurring timer
$timer = new TimerEvent(..., 1, 1);
$loop->start($timer);
if(/* some failure */)
{
throw new Exception();
}
$stop = new TimerEvent(function() use($timer)
{
$timer->stop();
}, 30);
$loop->add($stop)
return $stop;
}
$timer = doSomething();
// ... more code
$timer->invoke();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment