Skip to content

Commit

Permalink
Merge branch 'master' into 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jsor committed May 2, 2016
2 parents e8c20be + 16ff799 commit 08b491c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/functions.php
Expand Up @@ -121,14 +121,15 @@ function some(array $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
22 changes: 20 additions & 2 deletions tests/FunctionSomeTest.php
Expand Up @@ -146,7 +146,6 @@ public function shouldCancelOtherPendingInputArrayPromisesIfEnoughPromisesFulfil
->expects($this->never())
->method('__invoke');


$deferred = New Deferred($mock);
$deferred->resolve();

Expand All @@ -155,6 +154,25 @@ public function shouldCancelOtherPendingInputArrayPromisesIfEnoughPromisesFulfil
->expects($this->once())
->method('cancel');

some([$deferred->promise(), $mock2], 1)->cancel();
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 08b491c

Please sign in to comment.