Skip to content

Commit

Permalink
Merge pull request #48 from clue-labs/promise-v4
Browse files Browse the repository at this point in the history
[4.x] Forward compatibility with upcoming Promise v3
  • Loading branch information
WyriHaximus authored Jun 30, 2022
2 parents ed23203 + e68e9a8 commit 257634a
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"require": {
"php": ">=8.1",
"react/event-loop": "^1.2",
"react/promise": "^2.8 || ^1.2.1"
"react/promise": "^3.0 || ^2.8 || ^1.2.1"
},
"require-dev": {
"phpunit/phpunit": "^9.3"
Expand Down
12 changes: 5 additions & 7 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace React\Async;

use React\EventLoop\Loop;
use React\Promise\CancellablePromiseInterface;
use React\Promise\Deferred;
use React\Promise\Promise;
use React\Promise\PromiseInterface;
Expand Down Expand Up @@ -199,7 +197,7 @@ function async(callable $function): callable
}, function () use (&$fiber): void {
FiberMap::cancel($fiber);
$promise = FiberMap::getPromise($fiber);
if ($promise instanceof CancellablePromiseInterface) {
if ($promise instanceof PromiseInterface && \method_exists($promise, 'cancel')) {
$promise->cancel();
}
});
Expand Down Expand Up @@ -535,7 +533,7 @@ function parallel(iterable $tasks): PromiseInterface
$pending = [];
$deferred = new Deferred(function () use (&$pending) {
foreach ($pending as $promise) {
if ($promise instanceof CancellablePromiseInterface) {
if ($promise instanceof PromiseInterface && \method_exists($promise, 'cancel')) {
$promise->cancel();
}
}
Expand All @@ -549,7 +547,7 @@ function parallel(iterable $tasks): PromiseInterface
$deferred->reject($error);

foreach ($pending as $promise) {
if ($promise instanceof CancellablePromiseInterface) {
if ($promise instanceof PromiseInterface && \method_exists($promise, 'cancel')) {
$promise->cancel();
}
}
Expand Down Expand Up @@ -593,7 +591,7 @@ function series(iterable $tasks): PromiseInterface
{
$pending = null;
$deferred = new Deferred(function () use (&$pending) {
if ($pending instanceof CancellablePromiseInterface) {
if ($pending instanceof PromiseInterface && \method_exists($pending, 'cancel')) {
$pending->cancel();
}
$pending = null;
Expand Down Expand Up @@ -644,7 +642,7 @@ function waterfall(iterable $tasks): PromiseInterface
{
$pending = null;
$deferred = new Deferred(function () use (&$pending) {
if ($pending instanceof CancellablePromiseInterface) {
if ($pending instanceof PromiseInterface && \method_exists($pending, 'cancel')) {
$pending->cancel();
}
$pending = null;
Expand Down
2 changes: 1 addition & 1 deletion tests/SeriesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public function testSeriesWillCancelFirstPendingPromiseWhenCallingCancelOnResult
$tasks = array(
function () {
return new Promise(function ($resolve) {
$resolve();
$resolve(null);
});
},
function () use (&$cancelled) {
Expand Down
2 changes: 1 addition & 1 deletion tests/WaterfallTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public function testWaterfallWillCancelFirstPendingPromiseWhenCallingCancelOnRes
$tasks = array(
function () {
return new Promise(function ($resolve) {
$resolve();
$resolve(null);
});
},
function () use (&$cancelled) {
Expand Down

0 comments on commit 257634a

Please sign in to comment.