Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve forward compatibility with upcoming Promise v3 API #54

Merged
merged 1 commit into from
Mar 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 12 additions & 6 deletions tests/FunctionTimeoutTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class FunctionTimeoutTest extends TestCase
{
public function testResolvedWillResolveRightAway()
{
$promise = Promise\resolve();
$promise = Promise\resolve(null);

$promise = Timer\timeout($promise, 3);

Expand All @@ -19,7 +19,7 @@ public function testResolvedWillResolveRightAway()

public function testResolvedExpiredWillResolveRightAway()
{
$promise = Promise\resolve();
$promise = Promise\resolve(null);

$promise = Timer\timeout($promise, -1);

Expand All @@ -28,7 +28,7 @@ public function testResolvedExpiredWillResolveRightAway()

public function testResolvedWillNotStartTimer()
{
$promise = Promise\resolve();
$promise = Promise\resolve(null);

Timer\timeout($promise, 3);

Expand Down Expand Up @@ -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);

Expand All @@ -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);

Expand All @@ -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);

Expand Down