@@ -282,10 +282,10 @@ function coroutine(callable $function, ...$args): PromiseInterface
282282}
283283
284284/**
285- * @param array <callable():PromiseInterface<mixed,Exception>> $tasks
285+ * @param iterable <callable():PromiseInterface<mixed,Exception>> $tasks
286286 * @return PromiseInterface<array<mixed>,Exception>
287287 */
288- function parallel (array $ tasks ): PromiseInterface
288+ function parallel (iterable $ tasks ): PromiseInterface
289289{
290290 $ pending = [];
291291 $ deferred = new Deferred (function () use (&$ pending ) {
@@ -299,6 +299,10 @@ function parallel(array $tasks): PromiseInterface
299299 $ results = [];
300300 $ errored = false ;
301301
302+ if (!\is_array ($ tasks )) {
303+ $ tasks = \iterator_to_array ($ tasks );
304+ }
305+
302306 $ numTasks = count ($ tasks );
303307 if (0 === $ numTasks ) {
304308 $ deferred ->resolve ($ results );
@@ -340,10 +344,10 @@ function parallel(array $tasks): PromiseInterface
340344}
341345
342346/**
343- * @param array <callable():PromiseInterface<mixed,Exception>> $tasks
347+ * @param iterable <callable():PromiseInterface<mixed,Exception>> $tasks
344348 * @return PromiseInterface<array<mixed>,Exception>
345349 */
346- function series (array $ tasks ): PromiseInterface
350+ function series (iterable $ tasks ): PromiseInterface
347351{
348352 $ pending = null ;
349353 $ deferred = new Deferred (function () use (&$ pending ) {
@@ -354,6 +358,10 @@ function series(array $tasks): PromiseInterface
354358 });
355359 $ results = [];
356360
361+ if (!\is_array ($ tasks )) {
362+ $ tasks = \iterator_to_array ($ tasks );
363+ }
364+
357365 /** @var callable():void $next */
358366 $ taskCallback = function ($ result ) use (&$ results , &$ next ) {
359367 $ results [] = $ result ;
@@ -380,10 +388,10 @@ function series(array $tasks): PromiseInterface
380388}
381389
382390/**
383- * @param array <callable(mixed=):PromiseInterface<mixed,Exception>> $tasks
391+ * @param iterable <callable(mixed=):PromiseInterface<mixed,Exception>> $tasks
384392 * @return PromiseInterface<mixed,Exception>
385393 */
386- function waterfall (array $ tasks ): PromiseInterface
394+ function waterfall (iterable $ tasks ): PromiseInterface
387395{
388396 $ pending = null ;
389397 $ deferred = new Deferred (function () use (&$ pending ) {
@@ -393,6 +401,10 @@ function waterfall(array $tasks): PromiseInterface
393401 $ pending = null ;
394402 });
395403
404+ if (!\is_array ($ tasks )) {
405+ $ tasks = \iterator_to_array ($ tasks );
406+ }
407+
396408 /** @var callable $next */
397409 $ next = function ($ value = null ) use (&$ tasks , &$ next , $ deferred , &$ pending ) {
398410 if (0 === count ($ tasks )) {
0 commit comments