Skip to content

Commit 98909ce

Browse files
authored
Update README.md
1 parent 8da1cfd commit 98909ce

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

README.md

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,30 @@ ReactPHP async-await emulator with generator and yield
99
## Usage
1010
It makes possible writing
1111

12-
asyncRun(function ($init) {
13-
$res = yield asyncFunc($init);
14-
$res2 = yield all([asyncFunc($res+1), asyncFunc($res+1)]);
15-
$res3 = yield race([asyncFunc($res*2), asyncFunc($res2/2)]);
16-
return "wow".$init.$res.$res2.$res3;
17-
}, 0.1)->then(function($result){
18-
// ... $result is eq "wow".$res.$res2.$res3;
19-
});
20-
12+
```php
13+
asyncRun(function ($init) {
14+
$res = yield asyncFunc($init);
15+
$res2 = yield all([asyncFunc($res + 1), asyncFunc($res + 1)]);
16+
$res3 = yield race([asyncFunc($res * 2), asyncFunc($res2 / 2)]);
17+
return "wow" . $init . $res . $res2 . $res3;
18+
}, 0.1)->then(function ($result) {
19+
// ... $result is eq "wow".$res.$res2.$res3;
20+
});
21+
```
22+
2123
instead of
2224

23-
asyncFunc($init)->then(function($res){
24-
return all([asyncFunc($res+1), asyncFunc($res+1)]);
25-
})->then(function($res2){
26-
return yield race([asyncFunc(/* $res ?? */), asyncFunc($res2/2)]);
27-
})->then(function($res3){
28-
return "wow"./* $init ?? */ /* $res ??*/ /* $res2 ??*/ $res3
29-
})->then(function($result){
30-
// $result is eq "wow".$res3
31-
})
32-
25+
```php
26+
$init = 0.1;
27+
asyncFunc($init)->then(function ($res) {
28+
return all([asyncFunc($res + 1), asyncFunc($res + 1)]);
29+
})->then(function ($res2) {
30+
return yield race([asyncFunc(/* $res? */), asyncFunc($res2 / 2)]);
31+
})->then(function ($res3) {
32+
return "wow" ./* $init? */ /* $res?*/ /* $res2?*/ $res3
33+
})->then(function ($result) {
34+
// $result is eq "wow".$res3
35+
});
36+
```
37+
3338
For more see `spec`

0 commit comments

Comments
 (0)