From ca156837be6c4fe12c7a8291368521026132b52d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20L=C3=BCck?= Date: Fri, 25 Feb 2022 06:41:18 +0100 Subject: [PATCH] Improve forward compatibility with upcoming Promise v3 API --- src/functions.php | 2 +- tests/FunctionTimeoutTest.php | 18 ++++++++++++------ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/functions.php b/src/functions.php index 43665b2..474667d 100644 --- a/src/functions.php +++ b/src/functions.php @@ -236,7 +236,7 @@ function sleep($time, LoopInterface $loop = null) return new Promise(function ($resolve) use ($loop, $time, &$timer) { // resolve the promise when the timer fires in $time seconds $timer = $loop->addTimer($time, function () use ($resolve) { - $resolve(); + $resolve(null); }); }, function () use (&$timer, $loop) { // cancelling this promise will cancel the timer, clean the reference diff --git a/tests/FunctionTimeoutTest.php b/tests/FunctionTimeoutTest.php index b66cf6e..b794fe7 100644 --- a/tests/FunctionTimeoutTest.php +++ b/tests/FunctionTimeoutTest.php @@ -10,7 +10,7 @@ class FunctionTimeoutTest extends TestCase { public function testResolvedWillResolveRightAway() { - $promise = Promise\resolve(); + $promise = Promise\resolve(null); $promise = Timer\timeout($promise, 3); @@ -19,7 +19,7 @@ public function testResolvedWillResolveRightAway() public function testResolvedExpiredWillResolveRightAway() { - $promise = Promise\resolve(); + $promise = Promise\resolve(null); $promise = Timer\timeout($promise, -1); @@ -28,7 +28,7 @@ public function testResolvedExpiredWillResolveRightAway() public function testResolvedWillNotStartTimer() { - $promise = Promise\resolve(); + $promise = Promise\resolve(null); Timer\timeout($promise, 3); @@ -139,7 +139,9 @@ public function testCancelTimeoutWillCancelGivenPromise() public function testCancelGivenPromiseWillReject() { - $promise = new \React\Promise\Promise(function () { }, function ($resolve, $reject) { $reject(); }); + $promise = new \React\Promise\Promise(function () { }, function () { + throw new \RuntimeException(); + }); $timeout = Timer\timeout($promise, 0.01); @@ -151,7 +153,9 @@ public function testCancelGivenPromiseWillReject() public function testCancelTimeoutWillRejectIfGivenPromiseWillReject() { - $promise = new \React\Promise\Promise(function () { }, function ($resolve, $reject) { $reject(); }); + $promise = new \React\Promise\Promise(function () { }, function () { + throw new \RuntimeException(); + }); $timeout = Timer\timeout($promise, 0.01); @@ -163,7 +167,9 @@ public function testCancelTimeoutWillRejectIfGivenPromiseWillReject() public function testCancelTimeoutWillResolveIfGivenPromiseWillResolve() { - $promise = new \React\Promise\Promise(function () { }, function ($resolve, $reject) { $resolve(); }); + $promise = new \React\Promise\Promise(function () { }, function ($resolve) { + $resolve(null); + }); $timeout = Timer\timeout($promise, 0.01);