mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-13 13:25:16 +00:00
undo Promise covariant + improve array types
This commit is contained in:
parent
b78ff00418
commit
c250bb0da7
@ -27,7 +27,7 @@ use function count;
|
|||||||
use function spl_object_id;
|
use function spl_object_id;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @phpstan-template-covariant TValue
|
* @phpstan-template TValue
|
||||||
*/
|
*/
|
||||||
final class Promise{
|
final class Promise{
|
||||||
/**
|
/**
|
||||||
@ -61,20 +61,19 @@ final class Promise{
|
|||||||
* `$promises` indexed by the respective Promises' array keys.
|
* `$promises` indexed by the respective Promises' array keys.
|
||||||
*
|
*
|
||||||
* @template TPromiseValue
|
* @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 {
|
public static function all(array $promises) : Promise {
|
||||||
/** @phpstan-var PromiseResolver<array<int, TPromiseValue>> $resolver */
|
/** @phpstan-var PromiseResolver<array<TKey, TPromiseValue>> $resolver */
|
||||||
$resolver = new PromiseResolver();
|
$resolver = new PromiseResolver();
|
||||||
$values = [];
|
$values = [];
|
||||||
$toResolve = count($promises);
|
$toResolve = count($promises);
|
||||||
$continue = true;
|
$continue = true;
|
||||||
|
|
||||||
foreach($promises as $key => $promise){
|
foreach($promises as $key => $promise){
|
||||||
$values[$key] = null;
|
|
||||||
|
|
||||||
$promise->onCompletion(
|
$promise->onCompletion(
|
||||||
function(mixed $value) use ($resolver, $key, &$toResolve, &$continue, &$values) : void{
|
function(mixed $value) use ($resolver, $key, &$toResolve, &$continue, &$values) : void{
|
||||||
$values[$key] = $value;
|
$values[$key] = $value;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user