https://github.com/421p/stimer
Pausable timer for reactphp-event-loop
https://github.com/421p/stimer
async event-loop pause reactphp resume state timer
Last synced: 5 months ago
JSON representation
Pausable timer for reactphp-event-loop
- Host: GitHub
- URL: https://github.com/421p/stimer
- Owner: 421p
- Created: 2017-07-10T05:59:11.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2018-04-12T20:21:45.000Z (over 7 years ago)
- Last Synced: 2025-05-27T03:05:55.886Z (7 months ago)
- Topics: async, event-loop, pause, reactphp, resume, state, timer
- Language: PHP
- Homepage:
- Size: 5.86 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Stimer, a timer with pause/resume feature.
And immediately proceed to the samples:
Regular timer:
```php
$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:
```php
$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
```