2
2
3
3
namespace React \Async ;
4
4
5
- use React \EventLoop \Loop ;
6
- use React \Promise \CancellablePromiseInterface ;
7
5
use React \Promise \Deferred ;
8
6
use React \Promise \Promise ;
9
7
use React \Promise \PromiseInterface ;
@@ -199,7 +197,7 @@ function async(callable $function): callable
199
197
}, function () use (&$ fiber ): void {
200
198
FiberMap::cancel ($ fiber );
201
199
$ promise = FiberMap::getPromise ($ fiber );
202
- if ($ promise instanceof CancellablePromiseInterface ) {
200
+ if ($ promise instanceof PromiseInterface && \method_exists ( $ promise , ' cancel ' ) ) {
203
201
$ promise ->cancel ();
204
202
}
205
203
});
@@ -277,7 +275,7 @@ function await(PromiseInterface $promise): mixed
277
275
$ rejectedThrowable = null ;
278
276
$ lowLevelFiber = \Fiber::getCurrent ();
279
277
280
- if ($ lowLevelFiber !== null && FiberMap::isCancelled ($ lowLevelFiber ) && $ promise instanceof CancellablePromiseInterface ) {
278
+ if ($ lowLevelFiber !== null && FiberMap::isCancelled ($ lowLevelFiber ) && $ promise instanceof PromiseInterface && \method_exists ( $ promise , ' cancel ' ) ) {
281
279
$ promise ->cancel ();
282
280
}
283
281
@@ -486,7 +484,7 @@ function coroutine(callable $function, mixed ...$args): PromiseInterface
486
484
$ promise = null ;
487
485
$ deferred = new Deferred (function () use (&$ promise ) {
488
486
// 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 ' ) ) {
490
488
$ temp = $ promise ;
491
489
$ promise = null ;
492
490
$ temp ->cancel ();
@@ -541,7 +539,7 @@ function parallel(array $tasks): PromiseInterface
541
539
$ pending = [];
542
540
$ deferred = new Deferred (function () use (&$ pending ) {
543
541
foreach ($ pending as $ promise ) {
544
- if ($ promise instanceof CancellablePromiseInterface ) {
542
+ if ($ promise instanceof PromiseInterface && \method_exists ( $ promise , ' cancel ' ) ) {
545
543
$ promise ->cancel ();
546
544
}
547
545
}
@@ -560,7 +558,7 @@ function parallel(array $tasks): PromiseInterface
560
558
$ deferred ->reject ($ error );
561
559
562
560
foreach ($ pending as $ promise ) {
563
- if ($ promise instanceof CancellablePromiseInterface ) {
561
+ if ($ promise instanceof PromiseInterface && \method_exists ( $ promise , ' cancel ' ) ) {
564
562
$ promise ->cancel ();
565
563
}
566
564
}
@@ -598,7 +596,7 @@ function series(array $tasks): PromiseInterface
598
596
{
599
597
$ pending = null ;
600
598
$ deferred = new Deferred (function () use (&$ pending ) {
601
- if ($ pending instanceof CancellablePromiseInterface ) {
599
+ if ($ pending instanceof PromiseInterface && \method_exists ( $ pending , ' cancel ' ) ) {
602
600
$ pending ->cancel ();
603
601
}
604
602
$ pending = null ;
@@ -638,7 +636,7 @@ function waterfall(array $tasks): PromiseInterface
638
636
{
639
637
$ pending = null ;
640
638
$ deferred = new Deferred (function () use (&$ pending ) {
641
- if ($ pending instanceof CancellablePromiseInterface ) {
639
+ if ($ pending instanceof PromiseInterface && \method_exists ( $ pending , ' cancel ' ) ) {
642
640
$ pending ->cancel ();
643
641
}
644
642
$ pending = null ;
0 commit comments