1
0
mirror of https://github.com/danog/amp.git synced 2024-11-30 04:29:08 +01:00

Fix combinator functions, prepare tag 1.0.7

$struct->remaining may be negative in case of bare values passed to combinator functions
This commit is contained in:
Bob Weinand 2016-01-09 15:19:56 +01:00
parent 72683085c5
commit 5341a4cb92
2 changed files with 21 additions and 17 deletions

View File

@ -1,3 +1,9 @@
### 1.0.7
- Several combinator functions could result in a Promise already
resolved exception in case some values of the array weren't
Promises.
### 1.0.6
- Fix issue in NativeReactor causing `stop()` to be delayed by
@ -25,7 +31,7 @@
- Fix PHP7 issue in which top-level Throwables weren't caught
in certain coroutine contexts.
- Remove error suppression operater on optionally null option
- Remove error suppression operator on optionally null option
assignment to avoid spurious E_NOTICE output when custom
error handlers are used.

View File

@ -238,7 +238,7 @@ function all(array $promises) {
$onResolve = function ($error, $result, $cbData) {
list($struct, $key) = $cbData;
if (empty($struct->remaining)) {
if ($struct->remaining <= 0) {
// If the promisor already resolved we don't need to bother
return;
}
@ -305,16 +305,15 @@ function some(array $promises) {
} else {
$struct->results[$key] = $result;
}
if (--$struct->remaining) {
return;
}
if (empty($struct->results)) {
array_unshift($struct->errors, "All promises passed to Amp\some() failed");
$struct->promisor->fail(new CombinatorException(
implode("\n\n", $struct->errors)
));
} else {
$struct->promisor->succeed([$struct->errors, $struct->results]);
if (--$struct->remaining === 0) {
if (empty($struct->results)) {
array_unshift($struct->errors, "All promises passed to Amp\some() failed");
$struct->promisor->fail(new CombinatorException(
implode("\n\n", $struct->errors)
));
} else {
$struct->promisor->succeed([$struct->errors, $struct->results]);
}
}
};
@ -398,7 +397,7 @@ function first(array $promises) {
$onResolve = function ($error, $result, $cbData) {
$struct = $cbData;
if (empty($struct->remaining)) {
if ($struct->remaining === 0) {
return;
}
if (empty($error)) {
@ -446,7 +445,7 @@ function map(array $promises, callable $functor) {
$onResolve = function ($error, $result, $cbData) {
list($struct, $key) = $cbData;
if (empty($struct->remaining)) {
if ($struct->remaining <= 0) {
// If the promisor already resolved we don't need to bother
return;
}
@ -487,13 +486,12 @@ function map(array $promises, callable $functor) {
// @codeCoverageIgnoreStart
$struct->remaining = 0;
$struct->promisor->fail($e);
break;
// @codeCoverageIgnoreEnd
} catch (\Exception $e) {
// @TODO Remove this catch block once PHP5 support is no longer required
$struct->remaining = 0;
$struct->promisor->fail($e);
}
if ($struct->remaining === 0) {
break;
}
}
@ -531,7 +529,7 @@ function filter(array $promises, callable $functor = null) {
$onResolve = function ($error, $result, $cbData) {
list($struct, $key) = $cbData;
if (empty($struct->remaining)) {
if ($struct->remaining <= 0) {
// If the promisor already resolved we don't need to bother
return;
}