Skip to content

Commit 16ff799

Browse files
committed
Fix some() not cancelling pending promises when too much input promises reject
1 parent d9c1bf5 commit 16ff799

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/functions.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,15 @@ function some($promisesOrValues, $howMany)
128128
}
129129
};
130130

131-
$rejecter = function ($reason) use ($i, &$reasons, &$toReject, $toResolve, $reject) {
131+
$rejecter = function ($reason) use ($i, &$reasons, &$toReject, $toResolve, $reject, $cancellationQueue) {
132132
if ($toResolve < 1 || $toReject < 1) {
133133
return;
134134
}
135135

136136
$reasons[$i] = $reason;
137137

138138
if (0 === --$toReject) {
139+
$cancellationQueue();
139140
$reject($reasons);
140141
}
141142
};

tests/FunctionSomeTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,4 +226,23 @@ public function shouldCancelOtherPendingInputArrayPromisesIfEnoughPromisesFulfil
226226

227227
some([$deferred->promise(), $mock2], 1);
228228
}
229+
230+
/** @test */
231+
public function shouldCancelOtherPendingInputArrayPromisesIfEnoughPromisesReject()
232+
{
233+
$mock = $this->createCallableMock();
234+
$mock
235+
->expects($this->never())
236+
->method('__invoke');
237+
238+
$deferred = New Deferred($mock);
239+
$deferred->reject();
240+
241+
$mock2 = $this->getMock('React\Promise\CancellablePromiseInterface');
242+
$mock2
243+
->expects($this->once())
244+
->method('cancel');
245+
246+
some([$deferred->promise(), $mock2], 2);
247+
}
229248
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy