@@ -533,10 +533,10 @@ function coroutine(callable $function, mixed ...$args): PromiseInterface
533533}
534534
535535/**
536- * @param array <callable():PromiseInterface<mixed,Exception>> $tasks
536+ * @param iterable <callable():PromiseInterface<mixed,Exception>> $tasks
537537 * @return PromiseInterface<array<mixed>,Exception>
538538 */
539- function parallel (array $ tasks ): PromiseInterface
539+ function parallel (iterable $ tasks ): PromiseInterface
540540{
541541 $ pending = [];
542542 $ deferred = new Deferred (function () use (&$ pending ) {
@@ -550,6 +550,10 @@ function parallel(array $tasks): PromiseInterface
550550 $ results = [];
551551 $ errored = false ;
552552
553+ if (!\is_array ($ tasks )) {
554+ $ tasks = \iterator_to_array ($ tasks );
555+ }
556+
553557 $ numTasks = count ($ tasks );
554558 if (0 === $ numTasks ) {
555559 $ deferred ->resolve ($ results );
@@ -591,10 +595,10 @@ function parallel(array $tasks): PromiseInterface
591595}
592596
593597/**
594- * @param array <callable():PromiseInterface<mixed,Exception>> $tasks
598+ * @param iterable <callable():PromiseInterface<mixed,Exception>> $tasks
595599 * @return PromiseInterface<array<mixed>,Exception>
596600 */
597- function series (array $ tasks ): PromiseInterface
601+ function series (iterable $ tasks ): PromiseInterface
598602{
599603 $ pending = null ;
600604 $ deferred = new Deferred (function () use (&$ pending ) {
@@ -605,6 +609,10 @@ function series(array $tasks): PromiseInterface
605609 });
606610 $ results = [];
607611
612+ if (!\is_array ($ tasks )) {
613+ $ tasks = \iterator_to_array ($ tasks );
614+ }
615+
608616 /** @var callable():void $next */
609617 $ taskCallback = function ($ result ) use (&$ results , &$ next ) {
610618 $ results [] = $ result ;
@@ -631,10 +639,10 @@ function series(array $tasks): PromiseInterface
631639}
632640
633641/**
634- * @param array <callable(mixed=):PromiseInterface<mixed,Exception>> $tasks
642+ * @param iterable <callable(mixed=):PromiseInterface<mixed,Exception>> $tasks
635643 * @return PromiseInterface<mixed,Exception>
636644 */
637- function waterfall (array $ tasks ): PromiseInterface
645+ function waterfall (iterable $ tasks ): PromiseInterface
638646{
639647 $ pending = null ;
640648 $ deferred = new Deferred (function () use (&$ pending ) {
@@ -644,6 +652,10 @@ function waterfall(array $tasks): PromiseInterface
644652 $ pending = null ;
645653 });
646654
655+ if (!\is_array ($ tasks )) {
656+ $ tasks = \iterator_to_array ($ tasks );
657+ }
658+
647659 /** @var callable $next */
648660 $ next = function ($ value = null ) use (&$ tasks , &$ next , $ deferred , &$ pending ) {
649661 if (0 === count ($ tasks )) {
0 commit comments