Skip to content

Commit 843ebc2

Browse files
authored
Merge pull request #47 from clue-labs/promise-v3
[3.x] Forward compatibility with upcoming Promise v3
2 parents a1a0059 + e194657 commit 843ebc2

File tree

4 files changed

+8
-9
lines changed

4 files changed

+8
-9
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"require": {
2929
"php": ">=7.1",
3030
"react/event-loop": "^1.2",
31-
"react/promise": "^2.8 || ^1.2.1"
31+
"react/promise": "^3.0 || ^2.8 || ^1.2.1"
3232
},
3333
"require-dev": {
3434
"phpunit/phpunit": "^9.3 || ^7.5"

src/functions.php

+5-6
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace React\Async;
44

55
use React\EventLoop\Loop;
6-
use React\Promise\CancellablePromiseInterface;
76
use React\Promise\Deferred;
87
use React\Promise\PromiseInterface;
98
use function React\Promise\reject;
@@ -235,7 +234,7 @@ function coroutine(callable $function, ...$args): PromiseInterface
235234
$promise = null;
236235
$deferred = new Deferred(function () use (&$promise) {
237236
// cancel pending promise(s) as long as generator function keeps yielding
238-
while ($promise instanceof CancellablePromiseInterface) {
237+
while ($promise instanceof PromiseInterface && \method_exists($promise, 'cancel')) {
239238
$temp = $promise;
240239
$promise = null;
241240
$temp->cancel();
@@ -290,7 +289,7 @@ function parallel(array $tasks): PromiseInterface
290289
$pending = [];
291290
$deferred = new Deferred(function () use (&$pending) {
292291
foreach ($pending as $promise) {
293-
if ($promise instanceof CancellablePromiseInterface) {
292+
if ($promise instanceof PromiseInterface && \method_exists($promise, 'cancel')) {
294293
$promise->cancel();
295294
}
296295
}
@@ -309,7 +308,7 @@ function parallel(array $tasks): PromiseInterface
309308
$deferred->reject($error);
310309

311310
foreach ($pending as $promise) {
312-
if ($promise instanceof CancellablePromiseInterface) {
311+
if ($promise instanceof PromiseInterface && \method_exists($promise, 'cancel')) {
313312
$promise->cancel();
314313
}
315314
}
@@ -347,7 +346,7 @@ function series(array $tasks): PromiseInterface
347346
{
348347
$pending = null;
349348
$deferred = new Deferred(function () use (&$pending) {
350-
if ($pending instanceof CancellablePromiseInterface) {
349+
if ($pending instanceof PromiseInterface && \method_exists($pending, 'cancel')) {
351350
$pending->cancel();
352351
}
353352
$pending = null;
@@ -387,7 +386,7 @@ function waterfall(array $tasks): PromiseInterface
387386
{
388387
$pending = null;
389388
$deferred = new Deferred(function () use (&$pending) {
390-
if ($pending instanceof CancellablePromiseInterface) {
389+
if ($pending instanceof PromiseInterface && \method_exists($pending, 'cancel')) {
391390
$pending->cancel();
392391
}
393392
$pending = null;

tests/SeriesTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function testSeriesWillCancelFirstPendingPromiseWhenCallingCancelOnResult
8787
$tasks = array(
8888
function () {
8989
return new Promise(function ($resolve) {
90-
$resolve();
90+
$resolve(null);
9191
});
9292
},
9393
function () use (&$cancelled) {

tests/WaterfallTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function testWaterfallWillCancelFirstPendingPromiseWhenCallingCancelOnRes
9494
$tasks = array(
9595
function () {
9696
return new Promise(function ($resolve) {
97-
$resolve();
97+
$resolve(null);
9898
});
9999
},
100100
function () use (&$cancelled) {

0 commit comments

Comments
 (0)