421p/stimer

React-Eventloop compatible pausable timer.

0.2 2018-04-12 20:20 UTC

This package is auto-updated.

Last update: 2024-03-23 12:15:33 UTC


README

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