diff --git a/README.md b/README.md index 76b5e49..3f47281 100644 --- a/README.md +++ b/README.md @@ -78,13 +78,15 @@ will still be blocked, but everything outside this function can be executed asynchronously without blocking: ```php -Loop::addTimer(0.5, React\Async\async(function() { +Loop::addTimer(0.5, React\Async\async(function () { echo 'a'; - React\async\await(React\Promise\Timer\sleep(1.0)); + React\Async\await(React\Promise\Timer\sleep(1.0)); echo 'c'; })); -Loop::addTimer(1.0, fn() => echo 'b'); +Loop::addTimer(1.0, function () { + echo 'b'; +}); // prints "a" at t=0.5s // prints "b" at t=1.0s @@ -98,13 +100,15 @@ In particular, this function does not "magically" make any blocking function non-blocking: ```php -Loop::addTimer(0.5, React\Async\async(function() { +Loop::addTimer(0.5, React\Async\async(function () { echo 'a'; sleep(1); // broken: using PHP's blocking sleep() for demonstration purposes echo 'c'; })); -Loop::addTimer(1.0, fn() => echo 'b'); +Loop::addTimer(1.0, function () { + echo 'b'; +}); // prints "a" at t=0.5s // prints "c" at t=1.5s: Correct timing, but wrong order @@ -216,7 +220,7 @@ that bubbles up through the fibers. ```php $promise = async(static function (): int { echo 'a'; - await(async(static function(): void { + await(async(static function (): void { echo 'b'; await(React\Promise\Timer\sleep(2)); echo 'c'; @@ -247,13 +251,15 @@ call. Everything inside this function will still be blocked, but everything outside this function can be executed asynchronously without blocking: ```php -Loop::addTimer(0.5, React\Async\async(function() { +Loop::addTimer(0.5, React\Async\async(function () { echo 'a'; - React\async\await(React\Promise\Timer\sleep(1.0)); + React\Async\await(React\Promise\Timer\sleep(1.0)); echo 'c'; })); -Loop::addTimer(1.0, fn() => echo 'b'); +Loop::addTimer(1.0, function () { + echo 'b'; +}); // prints "a" at t=0.5s // prints "b" at t=1.0s diff --git a/src/functions.php b/src/functions.php index 0532394..092115b 100644 --- a/src/functions.php +++ b/src/functions.php @@ -19,13 +19,15 @@ * asynchronously without blocking: * * ```php - * Loop::addTimer(0.5, React\Async\async(function() { + * Loop::addTimer(0.5, React\Async\async(function () { * echo 'a'; - * React\async\await(React\Promise\Timer\sleep(1.0)); + * React\Async\await(React\Promise\Timer\sleep(1.0)); * echo 'c'; * })); * - * Loop::addTimer(1.0, fn() => echo 'b'); + * Loop::addTimer(1.0, function () { + * echo 'b'; + * }); * * // prints "a" at t=0.5s * // prints "b" at t=1.0s @@ -39,13 +41,15 @@ * non-blocking: * * ```php - * Loop::addTimer(0.5, React\Async\async(function() { + * Loop::addTimer(0.5, React\Async\async(function () { * echo 'a'; * sleep(1); // broken: using PHP's blocking sleep() for demonstration purposes * echo 'c'; * })); * - * Loop::addTimer(1.0, fn() => echo 'b'); + * Loop::addTimer(1.0, function () { + * echo 'b'; + * }); * * // prints "a" at t=0.5s * // prints "c" at t=1.5s: Correct timing, but wrong order @@ -157,7 +161,7 @@ * ```php * $promise = async(static function (): int { * echo 'a'; - * await(async(static function(): void { + * await(async(static function (): void { * echo 'b'; * await(React\Promise\Timer\sleep(2)); * echo 'c'; @@ -227,13 +231,15 @@ function async(callable $function): callable * outside this function can be executed asynchronously without blocking: * * ```php - * Loop::addTimer(0.5, React\Async\async(function() { + * Loop::addTimer(0.5, React\Async\async(function () { * echo 'a'; - * React\async\await(React\Promise\Timer\sleep(1.0)); + * React\Async\await(React\Promise\Timer\sleep(1.0)); * echo 'c'; * })); * - * Loop::addTimer(1.0, fn() => echo 'b'); + * Loop::addTimer(1.0, function () { + * echo 'b'; + * }); * * // prints "a" at t=0.5s * // prints "b" at t=1.0s diff --git a/tests/AsyncTest.php b/tests/AsyncTest.php index 7b86bc8..7698b42 100644 --- a/tests/AsyncTest.php +++ b/tests/AsyncTest.php @@ -243,9 +243,9 @@ public function testCancelAsyncWillCancelNestedAwait() $promise = async(static function (): int { echo 'a'; - await(async(static function(): void { + await(async(static function (): void { echo 'b'; - await(async(static function(): void { + await(async(static function (): void { echo 'c'; await(new Promise(function () { }, function () { throw new \RuntimeException('Operation cancelled');