421p / stimer

Pausable timer for reactphp-event-loop

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Stimer, a timer with pause/resume feature.

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

About

Pausable timer for reactphp-event-loop


Languages

Language:PHP 100.0%