176176 * await($promise);
177177 * ```
178178 *
179- * @param callable $function
180- * @return callable(mixed ...): PromiseInterface<mixed>
179+ * @template T
180+ * @template TFulfilled as PromiseInterface<T>|T
181+ * @template A
182+ * @param (callable(): TFulfilled)|(callable(A): TFulfilled) $function
183+ * @return callable(mixed ...$args): PromiseInterface<T>
181184 * @since 4.0.0
182185 * @see coroutine()
183186 */
@@ -268,8 +271,9 @@ function async(callable $function): callable
268271 * }
269272 * ```
270273 *
271- * @param PromiseInterface $promise
272- * @return mixed returns whatever the promise resolves to
274+ * @template T
275+ * @param PromiseInterface<T> $promise
276+ * @return T
273277 * @throws \Exception when the promise is rejected with an `Exception`
274278 * @throws \Throwable when the promise is rejected with a `Throwable`
275279 * @throws \UnexpectedValueException when the promise is rejected with an unexpected value (Promise API v1 or v2 only)
@@ -279,6 +283,10 @@ function await(PromiseInterface $promise): mixed
279283 $ fiber = null ;
280284 $ resolved = false ;
281285 $ rejected = false ;
286+
287+ /**
288+ * @var T $resolvedValue
289+ */
282290 $ resolvedValue = null ;
283291 $ rejectedThrowable = null ;
284292 $ lowLevelFiber = \Fiber::getCurrent ();
@@ -292,6 +300,9 @@ function (mixed $value) use (&$resolved, &$resolvedValue, &$fiber, $lowLevelFibe
292300 /** @var ?\Fiber<mixed,mixed,mixed,mixed> $fiber */
293301 if ($ fiber === null ) {
294302 $ resolved = true ;
303+ /**
304+ * @var T $resolvedValue
305+ */
295306 $ resolvedValue = $ value ;
296307 return ;
297308 }
@@ -354,7 +365,11 @@ function (mixed $throwable) use (&$rejected, &$rejectedThrowable, &$fiber, $lowL
354365
355366 $ fiber = FiberFactory::create ();
356367
357- return $ fiber ->suspend ();
368+ /**
369+ * @var T $result
370+ */
371+ $ result = $ fiber ->suspend ();
372+ return $ result ;
358373}
359374
360375/**
@@ -609,9 +624,9 @@ function coroutine(callable $function, mixed ...$args): PromiseInterface
609624 return resolve ($ generator );
610625 }
611626
627+ /** @var ?PromiseInterface<mixed> $promise */
612628 $ promise = null ;
613629 $ deferred = new Deferred (function () use (&$ promise ) {
614- /** @var ?PromiseInterface $promise */
615630 if ($ promise instanceof PromiseInterface && \method_exists ($ promise , 'cancel ' )) {
616631 $ promise ->cancel ();
617632 }
@@ -660,12 +675,13 @@ function coroutine(callable $function, mixed ...$args): PromiseInterface
660675}
661676
662677/**
663- * @param iterable<callable():PromiseInterface<mixed>> $tasks
664- * @return PromiseInterface<array<mixed>>
678+ * @template T
679+ * @param iterable<callable():PromiseInterface<T>> $tasks
680+ * @return PromiseInterface<array<T>>
665681 */
666682function parallel (iterable $ tasks ): PromiseInterface
667683{
668- /** @var array<int,PromiseInterface> $pending */
684+ /** @var array<int,PromiseInterface<T> > $pending */
669685 $ pending = [];
670686 $ deferred = new Deferred (function () use (&$ pending ) {
671687 foreach ($ pending as $ promise ) {
@@ -720,14 +736,15 @@ function parallel(iterable $tasks): PromiseInterface
720736}
721737
722738/**
723- * @param iterable<callable():PromiseInterface<mixed>> $tasks
724- * @return PromiseInterface<array<mixed>>
739+ * @template T
740+ * @param iterable<callable():PromiseInterface<T>> $tasks
741+ * @return PromiseInterface<array<T>>
725742 */
726743function series (iterable $ tasks ): PromiseInterface
727744{
728745 $ pending = null ;
729746 $ deferred = new Deferred (function () use (&$ pending ) {
730- /** @var ?PromiseInterface $pending */
747+ /** @var ?PromiseInterface<T> $pending */
731748 if ($ pending instanceof PromiseInterface && \method_exists ($ pending , 'cancel ' )) {
732749 $ pending ->cancel ();
733750 }
@@ -774,14 +791,15 @@ function series(iterable $tasks): PromiseInterface
774791}
775792
776793/**
777- * @param iterable<(callable():PromiseInterface<mixed>)|(callable(mixed):PromiseInterface<mixed>)> $tasks
778- * @return PromiseInterface<mixed>
794+ * @template T
795+ * @param iterable<(callable():PromiseInterface<T>)|(callable(mixed):PromiseInterface<T>)> $tasks
796+ * @return PromiseInterface<T>
779797 */
780798function waterfall (iterable $ tasks ): PromiseInterface
781799{
782800 $ pending = null ;
783801 $ deferred = new Deferred (function () use (&$ pending ) {
784- /** @var ?PromiseInterface $pending */
802+ /** @var ?PromiseInterface<T> $pending */
785803 if ($ pending instanceof PromiseInterface && \method_exists ($ pending , 'cancel ' )) {
786804 $ pending ->cancel ();
787805 }
0 commit comments