Skip to content
Permalink
Browse files

Fix some() not cancelling pending promises when too much input promis…

…es reject
  • Loading branch information...
jsor committed May 1, 2016
1 parent d9c1bf5 commit 16ff799a3a749dd79faff36c5f3cfc11825daa8b
Showing with 21 additions and 1 deletion.
  1. +2 −1 src/functions.php
  2. +19 −0 tests/FunctionSomeTest.php
@@ -128,14 +128,15 @@ function some($promisesOrValues, $howMany)
}
};
$rejecter = function ($reason) use ($i, &$reasons, &$toReject, $toResolve, $reject) {
$rejecter = function ($reason) use ($i, &$reasons, &$toReject, $toResolve, $reject, $cancellationQueue) {
if ($toResolve < 1 || $toReject < 1) {
return;
}
$reasons[$i] = $reason;
if (0 === --$toReject) {
$cancellationQueue();
$reject($reasons);
}
};
@@ -226,4 +226,23 @@ public function shouldCancelOtherPendingInputArrayPromisesIfEnoughPromisesFulfil
some([$deferred->promise(), $mock2], 1);
}
/** @test */
public function shouldCancelOtherPendingInputArrayPromisesIfEnoughPromisesReject()
{
$mock = $this->createCallableMock();
$mock
->expects($this->never())
->method('__invoke');
$deferred = New Deferred($mock);
$deferred->reject();
$mock2 = $this->getMock('React\Promise\CancellablePromiseInterface');
$mock2
->expects($this->once())
->method('cancel');
some([$deferred->promise(), $mock2], 2);
}
}

0 comments on commit 16ff799

Please sign in to comment.
You can’t perform that action at this time.