Skip to content

Commit 82db0a4

Browse files
authored
Merge pull request #54 from clue-labs/promise3
Improve forward compatibility with upcoming Promise v3 API
2 parents 0bbbcc7 + ca15683 commit 82db0a4

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

src/functions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ function sleep($time, LoopInterface $loop = null)
236236
return new Promise(function ($resolve) use ($loop, $time, &$timer) {
237237
// resolve the promise when the timer fires in $time seconds
238238
$timer = $loop->addTimer($time, function () use ($resolve) {
239-
$resolve();
239+
$resolve(null);
240240
});
241241
}, function () use (&$timer, $loop) {
242242
// cancelling this promise will cancel the timer, clean the reference

tests/FunctionTimeoutTest.php

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class FunctionTimeoutTest extends TestCase
1010
{
1111
public function testResolvedWillResolveRightAway()
1212
{
13-
$promise = Promise\resolve();
13+
$promise = Promise\resolve(null);
1414

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

@@ -19,7 +19,7 @@ public function testResolvedWillResolveRightAway()
1919

2020
public function testResolvedExpiredWillResolveRightAway()
2121
{
22-
$promise = Promise\resolve();
22+
$promise = Promise\resolve(null);
2323

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

@@ -28,7 +28,7 @@ public function testResolvedExpiredWillResolveRightAway()
2828

2929
public function testResolvedWillNotStartTimer()
3030
{
31-
$promise = Promise\resolve();
31+
$promise = Promise\resolve(null);
3232

3333
Timer\timeout($promise, 3);
3434

@@ -139,7 +139,9 @@ public function testCancelTimeoutWillCancelGivenPromise()
139139

140140
public function testCancelGivenPromiseWillReject()
141141
{
142-
$promise = new \React\Promise\Promise(function () { }, function ($resolve, $reject) { $reject(); });
142+
$promise = new \React\Promise\Promise(function () { }, function () {
143+
throw new \RuntimeException();
144+
});
143145

144146
$timeout = Timer\timeout($promise, 0.01);
145147

@@ -151,7 +153,9 @@ public function testCancelGivenPromiseWillReject()
151153

152154
public function testCancelTimeoutWillRejectIfGivenPromiseWillReject()
153155
{
154-
$promise = new \React\Promise\Promise(function () { }, function ($resolve, $reject) { $reject(); });
156+
$promise = new \React\Promise\Promise(function () { }, function () {
157+
throw new \RuntimeException();
158+
});
155159

156160
$timeout = Timer\timeout($promise, 0.01);
157161

@@ -163,7 +167,9 @@ public function testCancelTimeoutWillRejectIfGivenPromiseWillReject()
163167

164168
public function testCancelTimeoutWillResolveIfGivenPromiseWillResolve()
165169
{
166-
$promise = new \React\Promise\Promise(function () { }, function ($resolve, $reject) { $resolve(); });
170+
$promise = new \React\Promise\Promise(function () { }, function ($resolve) {
171+
$resolve(null);
172+
});
167173

168174
$timeout = Timer\timeout($promise, 0.01);
169175

0 commit comments

Comments
 (0)