Skip to content

Commit 1150ee6

Browse files
author
Greg Bowler
authored
Release v0.1 (#2)
* Promise v1 * Badges * Documentation
1 parent 663ed13 commit 1150ee6

3 files changed

Lines changed: 293 additions & 40 deletions

File tree

README.md

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
Promise-based non-blocking operations.
2+
======================================
3+
4+
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.
5+
6+
This repository provides the concepts of a `Loop`, different `Timer` implementations and a publish-subscribe model for `Event` objects.
7+
8+
***
9+
10+
<a href="https://github.com/PhpGt/Async/actions" target="_blank">
11+
<img src="https://badge.status.php.gt/async-build" alt="PHP.Gt/Async build status" />
12+
</a>
13+
<a href="https://scrutinizer-ci.com/g/PhpGt/Async" target="_blank">
14+
<img src="https://badge.status.php.gt/async-quality" alt="PHP.Gt/Async code quality" />
15+
</a>
16+
<a href="https://scrutinizer-ci.com/g/PhpGt/Async" target="_blank">
17+
<img src="https://badge.status.php.gt/async-coverage" alt="PHP.Gt/Async code coverage" />
18+
</a>
19+
<a href="https://packagist.PhpGt/packages/PhpGt/Async" target="_blank">
20+
<img src="https://badge.status.php.gt/async-version" alt="PHP.Gt/Async latest release" />
21+
</a>
22+
<a href="http://www.php.gt/Async" target="_blank">
23+
<img src="https://badge.status.php.gt/async-docs" alt="PHP.Gt/Async documentation" />
24+
</a>
25+
26+
Example usage
27+
-------------
28+
29+
A loop with three individual timers at 1 second, 5 seconds and 10 seconds.
30+
31+
```php
32+
$timeAtScriptStart = microtime(true);
33+
34+
$timer = new IndividualTimer();
35+
$timer->addTriggerTime($timeAtScriptStart + 1);
36+
$timer->addTriggerTime($timeAtScriptStart + 5);
37+
$timer->addTriggerTime($timeAtScriptStart + 10);
38+
39+
$timer->addCallback(function() use($timeAtScriptStart) {
40+
$now = microtime(true);
41+
$secondsPassed = round($now - $timeAtScriptStart);
42+
echo "Number of seconds passed: $secondsPassed", PHP_EOL;
43+
});
44+
45+
$loop = new Loop();
46+
$loop->addTimer($timer);
47+
echo "Starting...", PHP_EOL;
48+
$loop->run();
49+
```

composer.json

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,9 @@
33
"description": "Promise-based non-blocking operations.",
44
"license": "MIT",
55

6-
"repositories": [
7-
{
8-
"type": "path",
9-
"url": "/home/g105b/Code/PhpGt/Promise",
10-
"options": {
11-
"symlink": true
12-
}
13-
}
14-
],
15-
166
"require": {
17-
"php": ">=7.4",
18-
"phpgt/promise": "dev-master"
7+
"php": ">=8.0",
8+
"phpgt/promise": "^1.0"
199
},
2010
"require-dev": {
2111
"phpunit/phpunit": "9.*",

0 commit comments

Comments
 (0)