Skip to content

Commit 02c3121

Browse files
committed
Optimize Promise v3 API compatibility to avoid hitting autoloader
1 parent ca15683 commit 02c3121

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

src/functions.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use React\EventLoop\Loop;
66
use React\EventLoop\LoopInterface;
7-
use React\Promise\CancellablePromiseInterface;
87
use React\Promise\Promise;
98
use React\Promise\PromiseInterface;
109

@@ -144,7 +143,7 @@ function timeout(PromiseInterface $promise, $time, LoopInterface $loop = null)
144143
// cancelling this promise will only try to cancel the input promise,
145144
// thus leaving responsibility to the input promise.
146145
$canceller = null;
147-
if ($promise instanceof CancellablePromiseInterface || (!\interface_exists('React\Promise\CancellablePromiseInterface') && \method_exists($promise, 'cancel'))) {
146+
if (\method_exists($promise, 'cancel')) {
148147
// pass promise by reference to clean reference after cancellation handler
149148
// has been invoked once in order to avoid garbage references in call stack.
150149
$canceller = function () use (&$promise) {
@@ -184,7 +183,7 @@ function timeout(PromiseInterface $promise, $time, LoopInterface $loop = null)
184183

185184
// try to invoke cancellation handler of input promise and then clean
186185
// reference in order to avoid garbage references in call stack.
187-
if ($promise instanceof CancellablePromiseInterface || (!\interface_exists('React\Promise\CancellablePromiseInterface') && \method_exists($promise, 'cancel'))) {
186+
if (\method_exists($promise, 'cancel')) {
188187
$promise->cancel();
189188
}
190189
$promise = null;

tests/FunctionTimeoutTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public function testRejectedWillNotStartTimer()
6464
public function testPendingWillRejectOnTimeout()
6565
{
6666
$promise = $this->getMockBuilder('React\Promise\PromiseInterface')->getMock();
67+
$promise->expects($this->once())->method('then')->willReturn($this->getMockBuilder('React\Promise\PromiseInterface')->getMock());
6768

6869
$promise = Timer\timeout($promise, 0.01);
6970

0 commit comments

Comments
 (0)