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

[3.x] Forward compatibility with upcoming Promise v3 #47

Merged
merged 1 commit into from
Jun 13, 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
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": ">=7.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 || ^7.5"
Expand Down
11 changes: 5 additions & 6 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace React\Async;

use React\EventLoop\Loop;
use React\Promise\CancellablePromiseInterface;
use React\Promise\Deferred;
use React\Promise\PromiseInterface;
use function React\Promise\reject;
Expand Down Expand Up @@ -235,7 +234,7 @@ function coroutine(callable $function, ...$args): PromiseInterface
$promise = null;
$deferred = new Deferred(function () use (&$promise) {
// cancel pending promise(s) as long as generator function keeps yielding
while ($promise instanceof CancellablePromiseInterface) {
while ($promise instanceof PromiseInterface && \method_exists($promise, 'cancel')) {
$temp = $promise;
$promise = null;
$temp->cancel();
Expand Down Expand Up @@ -290,7 +289,7 @@ function parallel(array $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 @@ -309,7 +308,7 @@ function parallel(array $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 @@ -347,7 +346,7 @@ function series(array $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 @@ -387,7 +386,7 @@ function waterfall(array $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 @@ -87,7 +87,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 @@ -94,7 +94,7 @@ public function testWaterfallWillCancelFirstPendingPromiseWhenCallingCancelOnRes
$tasks = array(
function () {
return new Promise(function ($resolve) {
$resolve();
$resolve(null);
});
},
function () use (&$cancelled) {
Expand Down