@@ -282,10 +282,10 @@ function coroutine(callable $function, ...$args): PromiseInterface
282
282
}
283
283
284
284
/**
285
- * @param array <callable():PromiseInterface<mixed,Exception>> $tasks
285
+ * @param iterable <callable():PromiseInterface<mixed,Exception>> $tasks
286
286
* @return PromiseInterface<array<mixed>,Exception>
287
287
*/
288
- function parallel (array $ tasks ): PromiseInterface
288
+ function parallel (iterable $ tasks ): PromiseInterface
289
289
{
290
290
$ pending = [];
291
291
$ deferred = new Deferred (function () use (&$ pending ) {
@@ -299,6 +299,10 @@ function parallel(array $tasks): PromiseInterface
299
299
$ results = [];
300
300
$ errored = false ;
301
301
302
+ if (!\is_array ($ tasks )) {
303
+ $ tasks = \iterator_to_array ($ tasks );
304
+ }
305
+
302
306
$ numTasks = count ($ tasks );
303
307
if (0 === $ numTasks ) {
304
308
$ deferred ->resolve ($ results );
@@ -340,10 +344,10 @@ function parallel(array $tasks): PromiseInterface
340
344
}
341
345
342
346
/**
343
- * @param array <callable():PromiseInterface<mixed,Exception>> $tasks
347
+ * @param iterable <callable():PromiseInterface<mixed,Exception>> $tasks
344
348
* @return PromiseInterface<array<mixed>,Exception>
345
349
*/
346
- function series (array $ tasks ): PromiseInterface
350
+ function series (iterable $ tasks ): PromiseInterface
347
351
{
348
352
$ pending = null ;
349
353
$ deferred = new Deferred (function () use (&$ pending ) {
@@ -354,6 +358,10 @@ function series(array $tasks): PromiseInterface
354
358
});
355
359
$ results = [];
356
360
361
+ if (!\is_array ($ tasks )) {
362
+ $ tasks = \iterator_to_array ($ tasks );
363
+ }
364
+
357
365
/** @var callable():void $next */
358
366
$ taskCallback = function ($ result ) use (&$ results , &$ next ) {
359
367
$ results [] = $ result ;
@@ -380,10 +388,10 @@ function series(array $tasks): PromiseInterface
380
388
}
381
389
382
390
/**
383
- * @param array <callable(mixed=):PromiseInterface<mixed,Exception>> $tasks
391
+ * @param iterable <callable(mixed=):PromiseInterface<mixed,Exception>> $tasks
384
392
* @return PromiseInterface<mixed,Exception>
385
393
*/
386
- function waterfall (array $ tasks ): PromiseInterface
394
+ function waterfall (iterable $ tasks ): PromiseInterface
387
395
{
388
396
$ pending = null ;
389
397
$ deferred = new Deferred (function () use (&$ pending ) {
@@ -393,6 +401,10 @@ function waterfall(array $tasks): PromiseInterface
393
401
$ pending = null ;
394
402
});
395
403
404
+ if (!\is_array ($ tasks )) {
405
+ $ tasks = \iterator_to_array ($ tasks );
406
+ }
407
+
396
408
/** @var callable $next */
397
409
$ next = function ($ value = null ) use (&$ tasks , &$ next , $ deferred , &$ pending ) {
398
410
if (0 === count ($ tasks )) {
0 commit comments