Skip to content

Commit ee3f0e4

Browse files
committed
Improve examples for async() and await()
1 parent 257634a commit ee3f0e4

File tree

2 files changed

+22
-10
lines changed

2 files changed

+22
-10
lines changed

README.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,13 @@ asynchronously without blocking:
8080
```php
8181
Loop::addTimer(0.5, React\Async\async(function() {
8282
echo 'a';
83-
React\async\await(React\Promise\Timer\sleep(1.0));
83+
React\Async\await(React\Promise\Timer\sleep(1.0));
8484
echo 'c';
8585
}));
8686

87-
Loop::addTimer(1.0, fn() => echo 'b');
87+
Loop::addTimer(1.0, function() {
88+
echo 'b';
89+
});
8890

8991
// prints "a" at t=0.5s
9092
// prints "b" at t=1.0s
@@ -104,7 +106,9 @@ Loop::addTimer(0.5, React\Async\async(function() {
104106
echo 'c';
105107
}));
106108

107-
Loop::addTimer(1.0, fn() => echo 'b');
109+
Loop::addTimer(1.0, function() {
110+
echo 'b';
111+
});
108112

109113
// prints "a" at t=0.5s
110114
// prints "c" at t=1.5s: Correct timing, but wrong order
@@ -249,11 +253,13 @@ outside this function can be executed asynchronously without blocking:
249253
```php
250254
Loop::addTimer(0.5, React\Async\async(function() {
251255
echo 'a';
252-
React\async\await(React\Promise\Timer\sleep(1.0));
256+
React\Async\await(React\Promise\Timer\sleep(1.0));
253257
echo 'c';
254258
}));
255259

256-
Loop::addTimer(1.0, fn() => echo 'b');
260+
Loop::addTimer(1.0, function() {
261+
echo 'b';
262+
});
257263

258264
// prints "a" at t=0.5s
259265
// prints "b" at t=1.0s

src/functions.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@
2121
* ```php
2222
* Loop::addTimer(0.5, React\Async\async(function() {
2323
* echo 'a';
24-
* React\async\await(React\Promise\Timer\sleep(1.0));
24+
* React\Async\await(React\Promise\Timer\sleep(1.0));
2525
* echo 'c';
2626
* }));
2727
*
28-
* Loop::addTimer(1.0, fn() => echo 'b');
28+
* Loop::addTimer(1.0, function() {
29+
* echo 'b';
30+
* });
2931
*
3032
* // prints "a" at t=0.5s
3133
* // prints "b" at t=1.0s
@@ -45,7 +47,9 @@
4547
* echo 'c';
4648
* }));
4749
*
48-
* Loop::addTimer(1.0, fn() => echo 'b');
50+
* Loop::addTimer(1.0, function() {
51+
* echo 'b';
52+
* });
4953
*
5054
* // prints "a" at t=0.5s
5155
* // prints "c" at t=1.5s: Correct timing, but wrong order
@@ -229,11 +233,13 @@ function async(callable $function): callable
229233
* ```php
230234
* Loop::addTimer(0.5, React\Async\async(function() {
231235
* echo 'a';
232-
* React\async\await(React\Promise\Timer\sleep(1.0));
236+
* React\Async\await(React\Promise\Timer\sleep(1.0));
233237
* echo 'c';
234238
* }));
235239
*
236-
* Loop::addTimer(1.0, fn() => echo 'b');
240+
* Loop::addTimer(1.0, function() {
241+
* echo 'b';
242+
* });
237243
*
238244
* // prints "a" at t=0.5s
239245
* // prints "b" at t=1.0s

0 commit comments

Comments
 (0)