Skip to content

Commit

Permalink
Merge pull request #33 from clue-labs/promise-v3
Browse files Browse the repository at this point in the history
Forward compatibility with upcoming Promise v3
  • Loading branch information
SimonFrings authored Sep 29, 2022
2 parents 3f2ea2c + efb12d2 commit d9cb7fc
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
},
"require": {
"php": ">=5.3",
"react/promise": "^2.2.1 || ^1.2.1"
"react/promise": "^3 || ^2.2.1 || ^1.2.1"
},
"require-dev": {
"clue/block-react": "^1.0",
"clue/block-react": "^1.5",
"phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.35",
"react/event-loop": "^1.2",
"react/http": "^1.5"
"react/http": "^1.8"
}
}
11 changes: 5 additions & 6 deletions src/Queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Clue\React\Mq;

use React\Promise;
use React\Promise\CancellablePromiseInterface;
use React\Promise\Deferred;
use React\Promise\PromiseInterface;

Expand Down Expand Up @@ -124,7 +123,7 @@ public static function all($concurrency, array $jobs, $handler)
Promise\all($promises)->then($resolve, function ($e) use ($promises, $reject) {
// cancel all pending promises if a single promise fails
foreach (array_reverse($promises) as $promise) {
if ($promise instanceof CancellablePromiseInterface) {
if ($promise instanceof PromiseInterface && \method_exists($promise, 'cancel')) {
$promise->cancel();
}
}
Expand All @@ -135,7 +134,7 @@ public static function all($concurrency, array $jobs, $handler)
}, function () use ($promises) {
// cancel all pending promises on cancellation
foreach (array_reverse($promises) as $promise) {
if ($promise instanceof CancellablePromiseInterface) {
if ($promise instanceof PromiseInterface && \method_exists($promise, 'cancel')) {
$promise->cancel();
}
}
Expand Down Expand Up @@ -241,7 +240,7 @@ public static function any($concurrency, array $jobs, $handler)
Promise\any($promises)->then(function ($result) use ($promises, $resolve) {
// cancel all pending promises if a single result is ready
foreach (array_reverse($promises) as $promise) {
if ($promise instanceof CancellablePromiseInterface) {
if ($promise instanceof PromiseInterface && \method_exists($promise, 'cancel')) {
$promise->cancel();
}
}
Expand All @@ -252,7 +251,7 @@ public static function any($concurrency, array $jobs, $handler)
}, function () use ($promises) {
// cancel all pending promises on cancellation
foreach (array_reverse($promises) as $promise) {
if ($promise instanceof CancellablePromiseInterface) {
if ($promise instanceof PromiseInterface && \method_exists($promise, 'cancel')) {
$promise->cancel();
}
}
Expand Down Expand Up @@ -367,7 +366,7 @@ public function __invoke()

$deferred = new Deferred(function ($_, $reject) use (&$queue, $id, &$deferred) {
// forward cancellation to pending operation if it is currently executing
if (isset($deferred->pending) && $deferred->pending instanceof CancellablePromiseInterface) {
if (isset($deferred->pending) && $deferred->pending instanceof PromiseInterface && \method_exists($deferred->pending, 'cancel')) {
$deferred->pending->cancel();
}
unset($deferred->pending);
Expand Down
6 changes: 3 additions & 3 deletions tests/QueueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public function testCancelPendingOperationThatWasPreviousQueuedShouldInvokeItsCa

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

$deferred->resolve();
$deferred->resolve(null);
$second->cancel();
}

Expand All @@ -232,7 +232,7 @@ public function testCancelPendingOperationThatWasPreviouslyQueuedShouldRejectWit

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

$deferred->resolve();
$deferred->resolve(null);
$second->cancel();

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

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

$deferred->resolve();
$deferred->resolve(null);
$second->cancel();

$second->then($this->expectCallableNever(), $this->expectCallableNever());
Expand Down

0 comments on commit d9cb7fc

Please sign in to comment.