421p/stimer

与 React-Eventloop 兼容的可暂停计时器。

0.2 2018-04-12 20:20 UTC

This package is auto-updated.

Last update: 2024-09-23 13:18:24 UTC


README

立即转到示例

常规计时器

$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

周期性计时器

$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