Skip to content

Commit de1a946

Browse files
committed
Fix race() to return a forever pending promise when called with an empty array
1 parent 2dfc2e8 commit de1a946

3 files changed

Lines changed: 6 additions & 9 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ CHANGELOG for 3.x
1212
`some()`, `map()`, `reduce()`) now require an array of promises or values
1313
as input. Before, arrays and promises which resolve to an array were
1414
supported, other input types resolved to empty arrays or `null` (#35).
15+
* BC break: `race()` now returns a forever pending promise when called with
16+
an empty array (#83).
17+
The behavior is now also in line with the ES6 specification.
1518
* BC break: The interfaces `PromiseInterface`, `ExtendedPromiseInterface`
1619
and `CancellablePromiseInterface` have been merged into a single
1720
`PromiseInterface` (#75).

src/functions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ function all(array $promisesOrValues)
4444
function race(array $promisesOrValues)
4545
{
4646
if (!$promisesOrValues) {
47-
return resolve();
47+
return new Promise(function() {});
4848
}
4949

5050
$cancellationQueue = new Internal\CancellationQueue();

tests/FunctionRaceTest.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,11 @@
55
class FunctionRaceTest extends TestCase
66
{
77
/** @test */
8-
public function shouldResolveEmptyInput()
8+
public function shouldReturnForeverPendingPromiseForEmptyInput()
99
{
10-
$mock = $this->createCallableMock();
11-
$mock
12-
->expects($this->once())
13-
->method('__invoke')
14-
->with($this->identicalTo(null));
15-
1610
race(
1711
[]
18-
)->then($mock);
12+
)->then($this->expectCallableNever(), $this->expectCallableNever());
1913
}
2014

2115
/** @test */

0 commit comments

Comments
 (0)