项目作者: 421p

项目描述 :
Pausable timer for reactphp-event-loop
高级语言: PHP
项目地址: git://github.com/421p/stimer.git
创建时间: 2017-07-10T05:59:11Z
项目社区:https://github.com/421p/stimer

开源协议:

下载


Stimer, a timer with pause/resume feature.

And immediately proceed to the samples:

Regular timer:

  1. $loop = Factory::create();
  2. $interval = 5;
  3. $timer = new Timer($loop, $interval, function () { echo 'hello world'; });
  4. // ... 3 seconds
  5. $timer->pause();
  6. $timer->getLeftInterval(); // ~ 2 seconds
  7. // ... something happens
  8. $timer->resume();
  9. // ... 2 seconds
  10. // hello world

Periodic timer:

  1. $loop = Factory::create();
  2. $interval = 5;
  3. $timer = new PeriodicTimer($loop, $interval, function () { echo 'hello world'; });
  4. // ... 3 seconds
  5. $timer->pause();
  6. $timer->getLeftInterval(); // ~ 2 seconds
  7. // ... something happens
  8. $timer->resume();
  9. // ... 2 seconds
  10. // hello world
  11. // ... 5 seconds
  12. // hello world