Skip to content

Commit d9cb7fc

Browse files
authored
Merge pull request #33 from clue-labs/promise-v3
Forward compatibility with upcoming Promise v3
2 parents 3f2ea2c + efb12d2 commit d9cb7fc

File tree

3 files changed

+11
-12
lines changed

3 files changed

+11
-12
lines changed

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
},
1919
"require": {
2020
"php": ">=5.3",
21-
"react/promise": "^2.2.1 || ^1.2.1"
21+
"react/promise": "^3 || ^2.2.1 || ^1.2.1"
2222
},
2323
"require-dev": {
24-
"clue/block-react": "^1.0",
24+
"clue/block-react": "^1.5",
2525
"phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.35",
2626
"react/event-loop": "^1.2",
27-
"react/http": "^1.5"
27+
"react/http": "^1.8"
2828
}
2929
}

src/Queue.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace Clue\React\Mq;
44

55
use React\Promise;
6-
use React\Promise\CancellablePromiseInterface;
76
use React\Promise\Deferred;
87
use React\Promise\PromiseInterface;
98

@@ -124,7 +123,7 @@ public static function all($concurrency, array $jobs, $handler)
124123
Promise\all($promises)->then($resolve, function ($e) use ($promises, $reject) {
125124
// cancel all pending promises if a single promise fails
126125
foreach (array_reverse($promises) as $promise) {
127-
if ($promise instanceof CancellablePromiseInterface) {
126+
if ($promise instanceof PromiseInterface && \method_exists($promise, 'cancel')) {
128127
$promise->cancel();
129128
}
130129
}
@@ -135,7 +134,7 @@ public static function all($concurrency, array $jobs, $handler)
135134
}, function () use ($promises) {
136135
// cancel all pending promises on cancellation
137136
foreach (array_reverse($promises) as $promise) {
138-
if ($promise instanceof CancellablePromiseInterface) {
137+
if ($promise instanceof PromiseInterface && \method_exists($promise, 'cancel')) {
139138
$promise->cancel();
140139
}
141140
}
@@ -241,7 +240,7 @@ public static function any($concurrency, array $jobs, $handler)
241240
Promise\any($promises)->then(function ($result) use ($promises, $resolve) {
242241
// cancel all pending promises if a single result is ready
243242
foreach (array_reverse($promises) as $promise) {
244-
if ($promise instanceof CancellablePromiseInterface) {
243+
if ($promise instanceof PromiseInterface && \method_exists($promise, 'cancel')) {
245244
$promise->cancel();
246245
}
247246
}
@@ -252,7 +251,7 @@ public static function any($concurrency, array $jobs, $handler)
252251
}, function () use ($promises) {
253252
// cancel all pending promises on cancellation
254253
foreach (array_reverse($promises) as $promise) {
255-
if ($promise instanceof CancellablePromiseInterface) {
254+
if ($promise instanceof PromiseInterface && \method_exists($promise, 'cancel')) {
256255
$promise->cancel();
257256
}
258257
}
@@ -367,7 +366,7 @@ public function __invoke()
367366

368367
$deferred = new Deferred(function ($_, $reject) use (&$queue, $id, &$deferred) {
369368
// forward cancellation to pending operation if it is currently executing
370-
if (isset($deferred->pending) && $deferred->pending instanceof CancellablePromiseInterface) {
369+
if (isset($deferred->pending) && $deferred->pending instanceof PromiseInterface && \method_exists($deferred->pending, 'cancel')) {
371370
$deferred->pending->cancel();
372371
}
373372
unset($deferred->pending);

tests/QueueTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ public function testCancelPendingOperationThatWasPreviousQueuedShouldInvokeItsCa
217217

218218
$second = $q(new Promise(function () { }, $this->expectCallableOnce()));
219219

220-
$deferred->resolve();
220+
$deferred->resolve(null);
221221
$second->cancel();
222222
}
223223

@@ -232,7 +232,7 @@ public function testCancelPendingOperationThatWasPreviouslyQueuedShouldRejectWit
232232

233233
$second = $q(new Promise(function () { }, function () { throw new \BadMethodCallException(); }));
234234

235-
$deferred->resolve();
235+
$deferred->resolve(null);
236236
$second->cancel();
237237

238238
$second->then(null, $this->expectCallableOnceWith($this->isInstanceOf('BadMethodCallException')));
@@ -249,7 +249,7 @@ public function testCancelPendingOperationThatWasPreviouslyQueuedShouldNotReject
249249

250250
$second = $q(new Promise(function () { }, function () { }));
251251

252-
$deferred->resolve();
252+
$deferred->resolve(null);
253253
$second->cancel();
254254

255255
$second->then($this->expectCallableNever(), $this->expectCallableNever());

0 commit comments

Comments
 (0)