1515use React \Promise \PromiseInterface ;
1616use Temporal \Internal \Promise \CancellationQueue ;
1717use Temporal \Internal \Promise \Reasons ;
18+ use Temporal \Internal \Promise \RejectedValue ;
1819
1920use function React \Promise \race ;
2021use function React \Promise \reject ;
@@ -36,7 +37,7 @@ final class Promise
3637 */
3738 public static function all (iterable $ promises ): PromiseInterface
3839 {
39- return self ::map ($ promises , static fn ($ val ): mixed => $ val );
40+ return self ::map ($ promises , static fn (mixed $ val ): mixed => $ val );
4041 }
4142
4243 /**
@@ -205,10 +206,9 @@ static function (mixed $mapped) use ($i, &$values, &$toResolve, $resolve): void
205206 *
206207 * @param iterable<int, PromiseInterface|mixed> $promises
207208 * @param callable(mixed $current, mixed $carry, int $current, positive-int $items): mixed $reduce
208- * @param mixed $initial
209209 * @psalm-param PromiseReduceCallback $reduce
210210 */
211- public static function reduce (iterable $ promises , callable $ reduce , $ initial = null ): PromiseInterface
211+ public static function reduce (iterable $ promises , callable $ reduce , mixed $ initial = null ): PromiseInterface
212212 {
213213 $ cancellationQueue = new CancellationQueue ();
214214 $ cancellationQueue ->enqueue ($ promises );
@@ -273,32 +273,27 @@ static function (iterable $array) use (
273273 *
274274 * If `$promiseOrValue` is a promise, it will be returned as is.
275275 *
276- * @param null|mixed $promiseOrValue
276+ * @template T
277+ * @param PromiseInterface<T>|T $promiseOrValue
278+ * @return PromiseInterface<T>
277279 */
278- public static function resolve ($ promiseOrValue = null ): PromiseInterface
280+ public static function resolve (mixed $ promiseOrValue = null ): PromiseInterface
279281 {
280282 return resolve ($ promiseOrValue );
281283 }
282284
283285 /**
284286 * Creates a rejected promise for the supplied `$promiseOrValue`.
285287 *
286- * If `$promiseOrValue` is a value, it will be the rejection value of the
287- * returned promise.
288- *
289- * If `$promiseOrValue` is a promise, its completion value will be the rejected
290- * value of the returned promise.
291- *
292- * This can be useful in situations where you need to reject a promise without
293- * throwing an exception. For example, it allows you to propagate a rejection with
294- * the value of another promise.
288+ * If `$reason` is not a `\Throwable`, the returned promise will be
289+ * fulfilled with that value instead.
295290 *
296- * @param null|mixed $promiseOrValue
291+ * @param \Throwable $reason
297292 * @return PromiseInterface<never>
298293 */
299- public static function reject ($ promiseOrValue = null ): PromiseInterface
294+ public static function reject (mixed $ reason ): PromiseInterface
300295 {
301- return reject ($ promiseOrValue );
296+ return reject ($ reason instanceof \Throwable ? $ reason : new RejectedValue ( $ reason ) );
302297 }
303298
304299 /**
0 commit comments