undo Promise covariant + improve array types

This commit is contained in:
ShockedPlot7560 2023-10-22 15:08:50 +02:00
parent b78ff00418
commit c250bb0da7
No known key found for this signature in database
GPG Key ID: D7539B420F1FA86E

View File

@ -27,7 +27,7 @@ use function count;
use function spl_object_id;
/**
* @phpstan-template-covariant TValue
* @phpstan-template TValue
*/
final class Promise{
/**
@ -61,20 +61,19 @@ final class Promise{
* `$promises` indexed by the respective Promises' array keys.
*
* @template TPromiseValue
* @phpstan-param Promise<TPromiseValue>[] $promises
* @template TKey of array-key
* @phpstan-param array<TKey, Promise<TPromiseValue>> $promises
*
* @phpstan-return Promise<array<int, TPromiseValue>>
* @phpstan-return Promise<array<TKey, TPromiseValue>>
*/
public static function all(array $promises) : Promise {
/** @phpstan-var PromiseResolver<array<int, TPromiseValue>> $resolver */
/** @phpstan-var PromiseResolver<array<TKey, TPromiseValue>> $resolver */
$resolver = new PromiseResolver();
$values = [];
$toResolve = count($promises);
$continue = true;
foreach($promises as $key => $promise){
$values[$key] = null;
$promise->onCompletion(
function(mixed $value) use ($resolver, $key, &$toResolve, &$continue, &$values) : void{
$values[$key] = $value;