Skip to content

Commit e68e9a8

Browse files
committed
Forward compatibility with upcoming Promise v3
1 parent ed23203 commit e68e9a8

File tree

4 files changed

+8
-10
lines changed

4 files changed

+8
-10
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"require": {
2929
"php": ">=8.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"

src/functions.php

+5-7
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace React\Async;
44

5-
use React\EventLoop\Loop;
6-
use React\Promise\CancellablePromiseInterface;
75
use React\Promise\Deferred;
86
use React\Promise\Promise;
97
use React\Promise\PromiseInterface;
@@ -199,7 +197,7 @@ function async(callable $function): callable
199197
}, function () use (&$fiber): void {
200198
FiberMap::cancel($fiber);
201199
$promise = FiberMap::getPromise($fiber);
202-
if ($promise instanceof CancellablePromiseInterface) {
200+
if ($promise instanceof PromiseInterface && \method_exists($promise, 'cancel')) {
203201
$promise->cancel();
204202
}
205203
});
@@ -535,7 +533,7 @@ function parallel(iterable $tasks): PromiseInterface
535533
$pending = [];
536534
$deferred = new Deferred(function () use (&$pending) {
537535
foreach ($pending as $promise) {
538-
if ($promise instanceof CancellablePromiseInterface) {
536+
if ($promise instanceof PromiseInterface && \method_exists($promise, 'cancel')) {
539537
$promise->cancel();
540538
}
541539
}
@@ -549,7 +547,7 @@ function parallel(iterable $tasks): PromiseInterface
549547
$deferred->reject($error);
550548

551549
foreach ($pending as $promise) {
552-
if ($promise instanceof CancellablePromiseInterface) {
550+
if ($promise instanceof PromiseInterface && \method_exists($promise, 'cancel')) {
553551
$promise->cancel();
554552
}
555553
}
@@ -593,7 +591,7 @@ function series(iterable $tasks): PromiseInterface
593591
{
594592
$pending = null;
595593
$deferred = new Deferred(function () use (&$pending) {
596-
if ($pending instanceof CancellablePromiseInterface) {
594+
if ($pending instanceof PromiseInterface && \method_exists($pending, 'cancel')) {
597595
$pending->cancel();
598596
}
599597
$pending = null;
@@ -644,7 +642,7 @@ function waterfall(iterable $tasks): PromiseInterface
644642
{
645643
$pending = null;
646644
$deferred = new Deferred(function () use (&$pending) {
647-
if ($pending instanceof CancellablePromiseInterface) {
645+
if ($pending instanceof PromiseInterface && \method_exists($pending, 'cancel')) {
648646
$pending->cancel();
649647
}
650648
$pending = null;

tests/SeriesTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ public function testSeriesWillCancelFirstPendingPromiseWhenCallingCancelOnResult
174174
$tasks = array(
175175
function () {
176176
return new Promise(function ($resolve) {
177-
$resolve();
177+
$resolve(null);
178178
});
179179
},
180180
function () use (&$cancelled) {

tests/WaterfallTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ public function testWaterfallWillCancelFirstPendingPromiseWhenCallingCancelOnRes
188188
$tasks = array(
189189
function () {
190190
return new Promise(function ($resolve) {
191-
$resolve();
191+
$resolve(null);
192192
});
193193
},
194194
function () use (&$cancelled) {

0 commit comments

Comments
 (0)