Skip to content

Commit

Permalink
Revert automatic cancellation of pending collection promises
Browse files Browse the repository at this point in the history
This reverts 42d86b7
  • Loading branch information
jsor committed Jul 19, 2016
1 parent d3d5fde commit 1dead5d
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 25 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
CHANGELOG for 2.x
=================

* 2.4.2 (xxxx-xx-xx)

* Revert automatic cancellation of pending collection promises once the
output promise resolves. This was introduced in 42d86b7 and was both
unintended and backward incompatible.

* 2.4.1 (2016-05-03)

* Fix `some()` not cancelling pending promises when too much input promises
Expand Down
18 changes: 3 additions & 15 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,11 @@ function race($promisesOrValues)
return;
}

$fulfiller = function ($value) use ($cancellationQueue, $resolve) {
$cancellationQueue();
$resolve($value);
};

$rejecter = function ($reason) use ($cancellationQueue, $reject) {
$cancellationQueue();
$reject($reason);
};

foreach ($array as $promiseOrValue) {
$cancellationQueue->enqueue($promiseOrValue);

resolve($promiseOrValue)
->done($fulfiller, $rejecter, $notify);
->done($resolve, $reject, $notify);
}
}, $reject, $notify);
}, $cancellationQueue);
Expand Down Expand Up @@ -115,28 +105,26 @@ function some($promisesOrValues, $howMany)
$reasons = [];

foreach ($array as $i => $promiseOrValue) {
$fulfiller = function ($val) use ($i, &$values, &$toResolve, $toReject, $resolve, $cancellationQueue) {
$fulfiller = function ($val) use ($i, &$values, &$toResolve, $toReject, $resolve) {
if ($toResolve < 1 || $toReject < 1) {
return;
}

$values[$i] = $val;

if (0 === --$toResolve) {
$cancellationQueue();
$resolve($values);
}
};

$rejecter = function ($reason) use ($i, &$reasons, &$toReject, $toResolve, $reject, $cancellationQueue) {
$rejecter = function ($reason) use ($i, &$reasons, &$toReject, $toResolve, $reject) {
if ($toResolve < 1 || $toReject < 1) {
return;
}

$reasons[$i] = $reason;

if (0 === --$toReject) {
$cancellationQueue();
$reject($reasons);
}
};
Expand Down
4 changes: 2 additions & 2 deletions tests/FunctionAnyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public function shouldCancelInputArrayPromises()
}

/** @test */
public function shouldCancelOtherPendingInputArrayPromisesIfOnePromiseFulfills()
public function shouldNotCancelOtherPendingInputArrayPromisesIfOnePromiseFulfills()
{
$mock = $this->createCallableMock();
$mock
Expand All @@ -188,7 +188,7 @@ public function shouldCancelOtherPendingInputArrayPromisesIfOnePromiseFulfills()

$mock2 = $this->getMock('React\Promise\CancellablePromiseInterface');
$mock2
->expects($this->once())
->expects($this->never())
->method('cancel');

some([$deferred->promise(), $mock2], 1)->cancel();
Expand Down
8 changes: 4 additions & 4 deletions tests/FunctionRaceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public function shouldCancelInputArrayPromises()
}

/** @test */
public function shouldCancelOtherPendingInputArrayPromisesIfOnePromiseFulfills()
public function shouldNotCancelOtherPendingInputArrayPromisesIfOnePromiseFulfills()
{
$mock = $this->createCallableMock();
$mock
Expand All @@ -174,14 +174,14 @@ public function shouldCancelOtherPendingInputArrayPromisesIfOnePromiseFulfills()

$mock2 = $this->getMock('React\Promise\CancellablePromiseInterface');
$mock2
->expects($this->once())
->expects($this->never())
->method('cancel');

race([$deferred->promise(), $mock2])->cancel();
}

/** @test */
public function shouldCancelOtherPendingInputArrayPromisesIfOnePromiseRejects()
public function shouldNotCancelOtherPendingInputArrayPromisesIfOnePromiseRejects()
{
$mock = $this->createCallableMock();
$mock
Expand All @@ -193,7 +193,7 @@ public function shouldCancelOtherPendingInputArrayPromisesIfOnePromiseRejects()

$mock2 = $this->getMock('React\Promise\CancellablePromiseInterface');
$mock2
->expects($this->once())
->expects($this->never())
->method('cancel');

race([$deferred->promise(), $mock2])->cancel();
Expand Down
8 changes: 4 additions & 4 deletions tests/FunctionSomeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public function shouldCancelInputArrayPromises()
}

/** @test */
public function shouldCancelOtherPendingInputArrayPromisesIfEnoughPromisesFulfill()
public function shouldNotCancelOtherPendingInputArrayPromisesIfEnoughPromisesFulfill()
{
$mock = $this->createCallableMock();
$mock
Expand All @@ -221,14 +221,14 @@ public function shouldCancelOtherPendingInputArrayPromisesIfEnoughPromisesFulfil

$mock2 = $this->getMock('React\Promise\CancellablePromiseInterface');
$mock2
->expects($this->once())
->expects($this->never())
->method('cancel');

some([$deferred->promise(), $mock2], 1);
}

/** @test */
public function shouldCancelOtherPendingInputArrayPromisesIfEnoughPromisesReject()
public function shouldNotCancelOtherPendingInputArrayPromisesIfEnoughPromisesReject()
{
$mock = $this->createCallableMock();
$mock
Expand All @@ -240,7 +240,7 @@ public function shouldCancelOtherPendingInputArrayPromisesIfEnoughPromisesReject

$mock2 = $this->getMock('React\Promise\CancellablePromiseInterface');
$mock2
->expects($this->once())
->expects($this->never())
->method('cancel');

some([$deferred->promise(), $mock2], 2);
Expand Down

0 comments on commit 1dead5d

Please sign in to comment.