Skip to content

Commit 87035a0

Browse files
committed
Forward compatibility with upcoming Promise v3
1 parent cfd52ac commit 87035a0

File tree

4 files changed

+18
-14
lines changed

4 files changed

+18
-14
lines changed

composer.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@
2828
"require": {
2929
"php": ">=8.1",
3030
"react/event-loop": "^1.2",
31-
"react/promise": "^2.8 || ^1.2.1"
31+
"react/promise": "dev-queue-fibers as 3.0.0"
3232
},
3333
"require-dev": {
3434
"phpunit/phpunit": "^9.3",
35-
"react/promise-timer": "^1.8"
35+
"react/promise-timer": "^1.9"
3636
},
3737
"autoload": {
3838
"psr-4": {
@@ -44,5 +44,11 @@
4444
},
4545
"autoload-dev": {
4646
"psr-4": { "React\\Tests\\Async\\": "tests/" }
47-
}
47+
},
48+
"repositories": [
49+
{
50+
"type": "vcs",
51+
"url": "https://github.com/clue-labs/promise"
52+
}
53+
]
4854
}

src/functions.php

Lines changed: 7 additions & 9 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
});
@@ -277,7 +275,7 @@ function await(PromiseInterface $promise): mixed
277275
$rejectedThrowable = null;
278276
$lowLevelFiber = \Fiber::getCurrent();
279277

280-
if ($lowLevelFiber !== null && FiberMap::isCancelled($lowLevelFiber) && $promise instanceof CancellablePromiseInterface) {
278+
if ($lowLevelFiber !== null && FiberMap::isCancelled($lowLevelFiber) && $promise instanceof PromiseInterface && \method_exists($promise, 'cancel')) {
281279
$promise->cancel();
282280
}
283281

@@ -486,7 +484,7 @@ function coroutine(callable $function, mixed ...$args): PromiseInterface
486484
$promise = null;
487485
$deferred = new Deferred(function () use (&$promise) {
488486
// cancel pending promise(s) as long as generator function keeps yielding
489-
while ($promise instanceof CancellablePromiseInterface) {
487+
while ($promise instanceof PromiseInterface && \method_exists($promise, 'cancel')) {
490488
$temp = $promise;
491489
$promise = null;
492490
$temp->cancel();
@@ -541,7 +539,7 @@ function parallel(array $tasks): PromiseInterface
541539
$pending = [];
542540
$deferred = new Deferred(function () use (&$pending) {
543541
foreach ($pending as $promise) {
544-
if ($promise instanceof CancellablePromiseInterface) {
542+
if ($promise instanceof PromiseInterface && \method_exists($promise, 'cancel')) {
545543
$promise->cancel();
546544
}
547545
}
@@ -560,7 +558,7 @@ function parallel(array $tasks): PromiseInterface
560558
$deferred->reject($error);
561559

562560
foreach ($pending as $promise) {
563-
if ($promise instanceof CancellablePromiseInterface) {
561+
if ($promise instanceof PromiseInterface && \method_exists($promise, 'cancel')) {
564562
$promise->cancel();
565563
}
566564
}
@@ -598,7 +596,7 @@ function series(array $tasks): PromiseInterface
598596
{
599597
$pending = null;
600598
$deferred = new Deferred(function () use (&$pending) {
601-
if ($pending instanceof CancellablePromiseInterface) {
599+
if ($pending instanceof PromiseInterface && \method_exists($pending, 'cancel')) {
602600
$pending->cancel();
603601
}
604602
$pending = null;
@@ -638,7 +636,7 @@ function waterfall(array $tasks): PromiseInterface
638636
{
639637
$pending = null;
640638
$deferred = new Deferred(function () use (&$pending) {
641-
if ($pending instanceof CancellablePromiseInterface) {
639+
if ($pending instanceof PromiseInterface && \method_exists($pending, 'cancel')) {
642640
$pending->cancel();
643641
}
644642
$pending = null;

tests/SeriesTest.php

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

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