33namespace React \Async ;
44
55use React \EventLoop \Loop ;
6- use React \Promise \CancellablePromiseInterface ;
76use React \Promise \Deferred ;
87use React \Promise \PromiseInterface ;
98use function React \Promise \reject ;
@@ -235,7 +234,7 @@ function coroutine(callable $function, ...$args): PromiseInterface
235234 $ promise = null ;
236235 $ deferred = new Deferred (function () use (&$ promise ) {
237236 // cancel pending promise(s) as long as generator function keeps yielding
238- while ($ promise instanceof CancellablePromiseInterface ) {
237+ while ($ promise instanceof PromiseInterface && \method_exists ( $ promise , ' cancel ' ) ) {
239238 $ temp = $ promise ;
240239 $ promise = null ;
241240 $ temp ->cancel ();
@@ -290,7 +289,7 @@ function parallel(array $tasks): PromiseInterface
290289 $ pending = [];
291290 $ deferred = new Deferred (function () use (&$ pending ) {
292291 foreach ($ pending as $ promise ) {
293- if ($ promise instanceof CancellablePromiseInterface ) {
292+ if ($ promise instanceof PromiseInterface && \method_exists ( $ promise , ' cancel ' ) ) {
294293 $ promise ->cancel ();
295294 }
296295 }
@@ -309,7 +308,7 @@ function parallel(array $tasks): PromiseInterface
309308 $ deferred ->reject ($ error );
310309
311310 foreach ($ pending as $ promise ) {
312- if ($ promise instanceof CancellablePromiseInterface ) {
311+ if ($ promise instanceof PromiseInterface && \method_exists ( $ promise , ' cancel ' ) ) {
313312 $ promise ->cancel ();
314313 }
315314 }
@@ -347,7 +346,7 @@ function series(array $tasks): PromiseInterface
347346{
348347 $ pending = null ;
349348 $ deferred = new Deferred (function () use (&$ pending ) {
350- if ($ pending instanceof CancellablePromiseInterface ) {
349+ if ($ pending instanceof PromiseInterface && \method_exists ( $ pending , ' cancel ' ) ) {
351350 $ pending ->cancel ();
352351 }
353352 $ pending = null ;
@@ -387,7 +386,7 @@ function waterfall(array $tasks): PromiseInterface
387386{
388387 $ pending = null ;
389388 $ deferred = new Deferred (function () use (&$ pending ) {
390- if ($ pending instanceof CancellablePromiseInterface ) {
389+ if ($ pending instanceof PromiseInterface && \method_exists ( $ pending , ' cancel ' ) ) {
391390 $ pending ->cancel ();
392391 }
393392 $ pending = null ;
0 commit comments