Pausable timer for reactphp-event-loop
And immediately proceed to the samples:
Regular timer:
$loop = Factory::create();$interval = 5;$timer = new Timer($loop, $interval, function () { echo 'hello world'; });// ... 3 seconds$timer->pause();$timer->getLeftInterval(); // ~ 2 seconds// ... something happens$timer->resume();// ... 2 seconds// hello world
Periodic timer:
$loop = Factory::create();$interval = 5;$timer = new PeriodicTimer($loop, $interval, function () { echo 'hello world'; });// ... 3 seconds$timer->pause();$timer->getLeftInterval(); // ~ 2 seconds// ... something happens$timer->resume();// ... 2 seconds// hello world// ... 5 seconds// hello world