Promise: allow zero promises

not supporting this has caused problems every time this function has been used in reality so far (#6092 and #6333).
This commit is contained in:
Dylan K. Taylor 2024-11-13 14:55:14 +00:00
parent 3586bc42a9
commit fbeb017670
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -69,16 +69,17 @@ final class Promise{
*
* @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;