Skip to content

Commit

Permalink
Promise: allow zero promises
Browse files Browse the repository at this point in the history
not supporting this has caused problems every time this function has been used in reality so far (#6092 and #6333).
  • Loading branch information
dktapps committed Nov 13, 2024
1 parent 3586bc4 commit fbeb017
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/promise/Promise.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,17 @@ public function isResolved() : bool{
*
* @phpstan-template TPromiseValue
* @phpstan-template TKey of array-key
* @phpstan-param non-empty-array<TKey, Promise<TPromiseValue>> $promises
* @phpstan-param array<TKey, Promise<TPromiseValue>> $promises
*
* @phpstan-return Promise<array<TKey, TPromiseValue>>
*/
public static function all(array $promises) : Promise{
if(count($promises) === 0){
throw new \InvalidArgumentException("At least one promise must be provided");
}
/** @phpstan-var PromiseResolver<array<TKey, TPromiseValue>> $resolver */
$resolver = new PromiseResolver();
if(count($promises) === 0){
$resolver->resolve([]);
return $resolver->getPromise();
}
$values = [];
$toResolve = count($promises);
$continue = true;
Expand Down

0 comments on commit fbeb017

Please sign in to comment.