22
33namespace React \Async ;
44
5- use React \EventLoop \Loop ;
6- use React \Promise \CancellablePromiseInterface ;
75use React \Promise \Deferred ;
86use React \Promise \Promise ;
97use 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 ;
0 commit comments