Skip to content

Commit e627f1c

Browse files
authored
Merge pull request #46 from clue-labs/promise-v2
[2.x] Forward compatibility with upcoming Promise v3
2 parents 1fb9459 + 963a5a1 commit e627f1c

File tree

4 files changed

+7
-8
lines changed

4 files changed

+7
-8
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"require": {
2929
"php": ">=5.3.2",
3030
"react/event-loop": "^1.2",
31-
"react/promise": "^2.8 || ^1.2.1"
31+
"react/promise": "^3.0 || ^2.8 || ^1.2.1"
3232
},
3333
"require-dev": {
3434
"phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.35"

src/functions.php

+4-5
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
namespace React\Async;
44

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

@@ -108,7 +107,7 @@ function parallel(array $tasks)
108107
$pending = array();
109108
$deferred = new Deferred(function () use (&$pending) {
110109
foreach ($pending as $promise) {
111-
if ($promise instanceof CancellablePromiseInterface) {
110+
if ($promise instanceof PromiseInterface && \method_exists($promise, 'cancel')) {
112111
$promise->cancel();
113112
}
114113
}
@@ -127,7 +126,7 @@ function parallel(array $tasks)
127126
$deferred->reject($error);
128127

129128
foreach ($pending as $promise) {
130-
if ($promise instanceof CancellablePromiseInterface) {
129+
if ($promise instanceof PromiseInterface && \method_exists($promise, 'cancel')) {
131130
$promise->cancel();
132131
}
133132
}
@@ -165,7 +164,7 @@ function series(array $tasks)
165164
{
166165
$pending = null;
167166
$deferred = new Deferred(function () use (&$pending) {
168-
if ($pending instanceof CancellablePromiseInterface) {
167+
if ($pending instanceof PromiseInterface && \method_exists($pending, 'cancel')) {
169168
$pending->cancel();
170169
}
171170
$pending = null;
@@ -205,7 +204,7 @@ function waterfall(array $tasks)
205204
{
206205
$pending = null;
207206
$deferred = new Deferred(function () use (&$pending) {
208-
if ($pending instanceof CancellablePromiseInterface) {
207+
if ($pending instanceof PromiseInterface && \method_exists($pending, 'cancel')) {
209208
$pending->cancel();
210209
}
211210
$pending = null;

tests/SeriesTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public function testSeriesWillCancelFirstPendingPromiseWhenCallingCancelOnResult
8787
$tasks = array(
8888
function () {
8989
return new Promise(function ($resolve) {
90-
$resolve();
90+
$resolve(null);
9191
});
9292
},
9393
function () use (&$cancelled) {

tests/WaterfallTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public function testWaterfallWillCancelFirstPendingPromiseWhenCallingCancelOnRes
9494
$tasks = array(
9595
function () {
9696
return new Promise(function ($resolve) {
97-
$resolve();
97+
$resolve(null);
9898
});
9999
},
100100
function () use (&$cancelled) {

0 commit comments

Comments
 (0)