Skip to content

Commit 257634a

Browse files
authored
Merge pull request #48 from clue-labs/promise-v4
[4.x] Forward compatibility with upcoming Promise v3
2 parents ed23203 + e68e9a8 commit 257634a

File tree

4 files changed

+8
-10
lines changed

4 files changed

+8
-10
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
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

Lines changed: 5 additions & 7 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 1 addition & 1 deletion
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy