Skip to content

Commit

Permalink
Fix some() not cancelling pending promises when too much input promis…
Browse files Browse the repository at this point in the history
…es reject
  • Loading branch information
jsor committed May 2, 2016
1 parent d9c1bf5 commit 16ff799
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};
Expand Down
19 changes: 19 additions & 0 deletions tests/FunctionSomeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.