Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Forward compatibility with upcoming Promise v3 #33

Merged
merged 2 commits into from
Sep 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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