@@ -533,10 +533,10 @@ function coroutine(callable $function, mixed ...$args): PromiseInterface
533
533
}
534
534
535
535
/**
536
- * @param array <callable():PromiseInterface<mixed,Exception>> $tasks
536
+ * @param iterable <callable():PromiseInterface<mixed,Exception>> $tasks
537
537
* @return PromiseInterface<array<mixed>,Exception>
538
538
*/
539
- function parallel (array $ tasks ): PromiseInterface
539
+ function parallel (iterable $ tasks ): PromiseInterface
540
540
{
541
541
$ pending = [];
542
542
$ deferred = new Deferred (function () use (&$ pending ) {
@@ -550,6 +550,10 @@ function parallel(array $tasks): PromiseInterface
550
550
$ results = [];
551
551
$ errored = false ;
552
552
553
+ if (!\is_array ($ tasks )) {
554
+ $ tasks = \iterator_to_array ($ tasks );
555
+ }
556
+
553
557
$ numTasks = count ($ tasks );
554
558
if (0 === $ numTasks ) {
555
559
$ deferred ->resolve ($ results );
@@ -591,10 +595,10 @@ function parallel(array $tasks): PromiseInterface
591
595
}
592
596
593
597
/**
594
- * @param array <callable():PromiseInterface<mixed,Exception>> $tasks
598
+ * @param iterable <callable():PromiseInterface<mixed,Exception>> $tasks
595
599
* @return PromiseInterface<array<mixed>,Exception>
596
600
*/
597
- function series (array $ tasks ): PromiseInterface
601
+ function series (iterable $ tasks ): PromiseInterface
598
602
{
599
603
$ pending = null ;
600
604
$ deferred = new Deferred (function () use (&$ pending ) {
@@ -605,6 +609,10 @@ function series(array $tasks): PromiseInterface
605
609
});
606
610
$ results = [];
607
611
612
+ if (!\is_array ($ tasks )) {
613
+ $ tasks = \iterator_to_array ($ tasks );
614
+ }
615
+
608
616
/** @var callable():void $next */
609
617
$ taskCallback = function ($ result ) use (&$ results , &$ next ) {
610
618
$ results [] = $ result ;
@@ -631,10 +639,10 @@ function series(array $tasks): PromiseInterface
631
639
}
632
640
633
641
/**
634
- * @param array <callable(mixed=):PromiseInterface<mixed,Exception>> $tasks
642
+ * @param iterable <callable(mixed=):PromiseInterface<mixed,Exception>> $tasks
635
643
* @return PromiseInterface<mixed,Exception>
636
644
*/
637
- function waterfall (array $ tasks ): PromiseInterface
645
+ function waterfall (iterable $ tasks ): PromiseInterface
638
646
{
639
647
$ pending = null ;
640
648
$ deferred = new Deferred (function () use (&$ pending ) {
@@ -644,6 +652,10 @@ function waterfall(array $tasks): PromiseInterface
644
652
$ pending = null ;
645
653
});
646
654
655
+ if (!\is_array ($ tasks )) {
656
+ $ tasks = \iterator_to_array ($ tasks );
657
+ }
658
+
647
659
/** @var callable $next */
648
660
$ next = function ($ value = null ) use (&$ tasks , &$ next , $ deferred , &$ pending ) {
649
661
if (0 === count ($ tasks )) {
0 commit comments