Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/phpgt/async
Promise-based non-blocking operations.
https://github.com/phpgt/async
async async-await async-programming asynchronous asynchronous-programming php-async phpgt
Last synced: about 6 hours ago
JSON representation
Promise-based non-blocking operations.
- Host: GitHub
- URL: https://github.com/phpgt/async
- Owner: PhpGt
- Created: 2020-11-11T11:13:17.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2023-07-01T11:03:00.000Z (over 1 year ago)
- Last Synced: 2024-11-14T13:42:17.162Z (3 days ago)
- Topics: async, async-await, async-programming, asynchronous, asynchronous-programming, php-async, phpgt
- Language: PHP
- Homepage:
- Size: 97.7 KB
- Stars: 0
- Watchers: 3
- Forks: 2
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
Awesome Lists containing this project
README
Promise-based non-blocking operations.
======================================To be able to run asynchronous code in PHP, a loop needs to run in the background to observe and dispatch events, and handle the resolution of promises.
This repository provides the concepts of a `Loop`, different `Timer` implementations and a publish-subscribe model for `Event` objects.
***
Example usage
-------------A loop with three individual timers at 1 second, 5 seconds and 10 seconds.
```php
$timeAtScriptStart = microtime(true);$timer = new IndividualTimer();
$timer->addTriggerTime($timeAtScriptStart + 1);
$timer->addTriggerTime($timeAtScriptStart + 5);
$timer->addTriggerTime($timeAtScriptStart + 10);$timer->addCallback(function() use($timeAtScriptStart) {
$now = microtime(true);
$secondsPassed = round($now - $timeAtScriptStart);
echo "Number of seconds passed: $secondsPassed", PHP_EOL;
});$loop = new Loop();
$loop->addTimer($timer);
echo "Starting...", PHP_EOL;
$loop->run();
```