176176 * await($promise);
177177 * ```
178178 *
179- * @param callable(mixed ...$args):mixed $function
180- * @return callable(): PromiseInterface<mixed>
179+ * @param callable $function
180+ * @return callable(mixed ... ): PromiseInterface<mixed>
181181 * @since 4.0.0
182182 * @see coroutine()
183183 */
@@ -192,6 +192,7 @@ function async(callable $function): callable
192192 } catch (\Throwable $ exception ) {
193193 $ reject ($ exception );
194194 } finally {
195+ assert ($ fiber instanceof \Fiber);
195196 FiberMap::unregister ($ fiber );
196197 }
197198 });
@@ -200,6 +201,7 @@ function async(callable $function): callable
200201
201202 $ fiber ->start ();
202203 }, function () use (&$ fiber ): void {
204+ assert ($ fiber instanceof \Fiber);
203205 FiberMap::cancel ($ fiber );
204206 $ promise = FiberMap::getPromise ($ fiber );
205207 if ($ promise instanceof PromiseInterface && \method_exists ($ promise , 'cancel ' )) {
@@ -287,6 +289,7 @@ function (mixed $value) use (&$resolved, &$resolvedValue, &$fiber, $lowLevelFibe
287289 FiberMap::unsetPromise ($ lowLevelFiber , $ promise );
288290 }
289291
292+ /** @var ?\Fiber<mixed,mixed,mixed,mixed> $fiber */
290293 if ($ fiber === null ) {
291294 $ resolved = true ;
292295 $ resolvedValue = $ value ;
@@ -309,6 +312,7 @@ function (mixed $throwable) use (&$rejected, &$rejectedThrowable, &$fiber, $lowL
309312 // what a lovely piece of code!
310313 $ r = new \ReflectionProperty ('Exception ' , 'trace ' );
311314 $ trace = $ r ->getValue ($ throwable );
315+ assert (\is_array ($ trace ));
312316
313317 // Exception trace arguments only available when zend.exception_ignore_args is not set
314318 // @codeCoverageIgnoreStart
@@ -340,6 +344,7 @@ function (mixed $throwable) use (&$rejected, &$rejectedThrowable, &$fiber, $lowL
340344 }
341345
342346 if ($ rejected ) {
347+ assert ($ rejectedThrowable instanceof \Throwable);
343348 throw $ rejectedThrowable ;
344349 }
345350
@@ -587,7 +592,7 @@ function delay(float $seconds): void
587592 * });
588593 * ```
589594 *
590- * @param callable(...$args):\Generator<mixed,PromiseInterface,mixed,mixed> $function
595+ * @param callable(mixed ...$args):( \Generator<mixed,PromiseInterface,mixed,mixed>|mixed) $function
591596 * @param mixed ...$args Optional list of additional arguments that will be passed to the given `$function` as is
592597 * @return PromiseInterface<mixed>
593598 * @since 3.0.0
@@ -606,6 +611,7 @@ function coroutine(callable $function, mixed ...$args): PromiseInterface
606611
607612 $ promise = null ;
608613 $ deferred = new Deferred (function () use (&$ promise ) {
614+ /** @var ?PromiseInterface $promise */
609615 if ($ promise instanceof PromiseInterface && \method_exists ($ promise , 'cancel ' )) {
610616 $ promise ->cancel ();
611617 }
@@ -626,6 +632,7 @@ function coroutine(callable $function, mixed ...$args): PromiseInterface
626632 return ;
627633 }
628634
635+ /** @var mixed $promise */
629636 $ promise = $ generator ->current ();
630637 if (!$ promise instanceof PromiseInterface) {
631638 $ next = null ;
@@ -635,6 +642,7 @@ function coroutine(callable $function, mixed ...$args): PromiseInterface
635642 return ;
636643 }
637644
645+ assert ($ next instanceof \Closure);
638646 $ promise ->then (function ($ value ) use ($ generator , $ next ) {
639647 $ generator ->send ($ value );
640648 $ next ();
@@ -657,6 +665,7 @@ function coroutine(callable $function, mixed ...$args): PromiseInterface
657665 */
658666function parallel (iterable $ tasks ): PromiseInterface
659667{
668+ /** @var array<int,PromiseInterface> $pending */
660669 $ pending = [];
661670 $ deferred = new Deferred (function () use (&$ pending ) {
662671 foreach ($ pending as $ promise ) {
@@ -718,6 +727,7 @@ function series(iterable $tasks): PromiseInterface
718727{
719728 $ pending = null ;
720729 $ deferred = new Deferred (function () use (&$ pending ) {
730+ /** @var ?PromiseInterface $pending */
721731 if ($ pending instanceof PromiseInterface && \method_exists ($ pending , 'cancel ' )) {
722732 $ pending ->cancel ();
723733 }
@@ -730,9 +740,9 @@ function series(iterable $tasks): PromiseInterface
730740 assert ($ tasks instanceof \Iterator);
731741 }
732742
733- /** @var callable():void $next */
734743 $ taskCallback = function ($ result ) use (&$ results , &$ next ) {
735744 $ results [] = $ result ;
745+ /** @var \Closure $next */
736746 $ next ();
737747 };
738748
@@ -746,9 +756,11 @@ function series(iterable $tasks): PromiseInterface
746756 $ task = $ tasks ->current ();
747757 $ tasks ->next ();
748758 } else {
759+ assert (\is_array ($ tasks ));
749760 $ task = \array_shift ($ tasks );
750761 }
751762
763+ assert (\is_callable ($ task ));
752764 $ promise = \call_user_func ($ task );
753765 assert ($ promise instanceof PromiseInterface);
754766 $ pending = $ promise ;
@@ -762,13 +774,14 @@ function series(iterable $tasks): PromiseInterface
762774}
763775
764776/**
765- * @param iterable<callable(mixed=) :PromiseInterface<mixed>> $tasks
777+ * @param iterable<( callable():PromiseInterface< mixed>)|(callable(mixed) :PromiseInterface<mixed>) > $tasks
766778 * @return PromiseInterface<mixed>
767779 */
768780function waterfall (iterable $ tasks ): PromiseInterface
769781{
770782 $ pending = null ;
771783 $ deferred = new Deferred (function () use (&$ pending ) {
784+ /** @var ?PromiseInterface $pending */
772785 if ($ pending instanceof PromiseInterface && \method_exists ($ pending , 'cancel ' )) {
773786 $ pending ->cancel ();
774787 }
@@ -791,9 +804,11 @@ function waterfall(iterable $tasks): PromiseInterface
791804 $ task = $ tasks ->current ();
792805 $ tasks ->next ();
793806 } else {
807+ assert (\is_array ($ tasks ));
794808 $ task = \array_shift ($ tasks );
795809 }
796810
811+ assert (\is_callable ($ task ));
797812 $ promise = \call_user_func_array ($ task , func_get_args ());
798813 assert ($ promise instanceof PromiseInterface);
799814 $ pending = $ promise ;
0 commit comments