Skip to content

Commit dbb2364

Browse files
committedAug 7, 2023
Add support for react/promise v3
With v3 come a whole list of [changes](https://github.com/reactphp/promise/releases/tag/v3.0.0) including end of promise chain detection, the removal of the `CancellablePromiseInterface` interface, and type templating.
1 parent 2a2c228 commit dbb2364

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed
 

‎composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
],
2222
"require": {
2323
"php": ">=7.0.0",
24-
"react/promise": "~2.2"
24+
"react/promise": "^3 || ~2.2"
2525
},
2626
"require-dev": {
2727
"satooshi/php-coveralls": "~1.0",

‎phpstan.neon.dist

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
parameters:
2+
level: max
3+
4+
paths:
5+
- test/types/
6+
7+
fileExtensions:
8+
- php

‎src/React/Promise.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Rx\React;
44

5-
use React\Promise\CancellablePromiseInterface;
65
use React\Promise\Promise as ReactPromise;
76
use React\Promise\PromiseInterface;
87
use Rx\Disposable\CallbackDisposable;
@@ -11,6 +10,7 @@
1110
use Rx\Observable\AnonymousObservable;
1211
use Rx\Subject\AsyncSubject;
1312
use React\Promise\Deferred;
13+
use Throwable;
1414

1515
final class Promise
1616
{
@@ -32,7 +32,7 @@ public static function resolved($value): ReactPromise
3232
public static function rejected($exception): ReactPromise
3333
{
3434
$d = new Deferred();
35-
$d->reject($exception);
35+
$d->reject($exception instanceof Throwable ? $exception : new RejectedPromiseException($exception));
3636
return $d->promise();
3737
}
3838

@@ -94,7 +94,7 @@ function ($error) use ($subject) {
9494
$disp = $subject->subscribe($observer);
9595
return new CallbackDisposable(function () use ($p, $disp) {
9696
$disp->dispose();
97-
if ($p instanceof CancellablePromiseInterface) {
97+
if (\method_exists($p, 'cancel')) {
9898
$p->cancel();
9999
}
100100
});

‎test/Rx/Functional/Promise/FromPromiseTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function () {
4040
*/
4141
public function from_promise_failure()
4242
{
43-
$p = \React\Promise\reject('error');
43+
$p = \React\Promise\reject(new RejectedPromiseException('error'));
4444

4545
$source = Observable::fromPromise($p);
4646

0 commit comments

Comments
 (0)