mirror of
https://github.com/danog/amp.git
synced 2024-11-30 04:29:08 +01:00
Fix #172 - Preserve Promise order within combinator functions
This commit is contained in:
parent
955e3e5d0a
commit
7837d8ce08
@ -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
|
||||
|
||||
|
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user