diff --git a/CHANGELOG.md b/CHANGELOG.md index cd8d57b..5ca3596 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ### Unreleased - `Loop::set()` replaces the current driver with a dummy driver for the time of `gc_collect_cycles()` now. This allows cyclic references to be cleaned up properly before the new driver is set. Without such a fix, cyclic references might have been cleaned up later, e.g. cancelling their watcher IDs on the new loop, thereby cancelling the wrong watchers. + - Promise combinator functions (`all(), `any()`, `first()`, `some()`) now preserve order of the given `$promises` array argument. ### 2.0.2 diff --git a/lib/functions.php b/lib/functions.php index 17a4d2a..8d024a5 100644 --- a/lib/functions.php +++ b/lib/functions.php @@ -284,6 +284,7 @@ namespace Amp\Promise { throw createTypeError([Promise::class, ReactPromise::class], $promise); } + $values[$key] = null; // add entry to array to preserve order $promise->onResolve(function ($exception, $value) use (&$deferred, &$values, &$pending, $key) { if ($pending === 0) { return; @@ -333,6 +334,7 @@ namespace Amp\Promise { throw createTypeError([Promise::class, ReactPromise::class], $promise); } + $exceptions[$key] = null; // add entry to array to preserve order $promise->onResolve(function ($error, $value) use (&$deferred, &$exceptions, &$pending, &$resolved, $key) { if ($pending === 0) { return; @@ -394,13 +396,16 @@ namespace Amp\Promise { throw createTypeError([Promise::class, ReactPromise::class], $promise); } + $values[$key] = $exceptions[$key] = null; // add entry to arrays to preserve order $promise->onResolve(function ($exception, $value) use ( &$values, &$exceptions, &$pending, $key, $required, $deferred ) { if ($exception) { $exceptions[$key] = $exception; + unset($values[$key]); } else { $values[$key] = $value; + unset($exceptions[$key]); } if (0 === --$pending) {