Skip to content

Commit

Permalink
Add support for react/promise v3
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
WyriHaximus committed Aug 7, 2023
1 parent 2a2c228 commit dbb2364
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
],
"require": {
"php": ">=7.0.0",
"react/promise": "~2.2"
"react/promise": "^3 || ~2.2"
},
"require-dev": {
"satooshi/php-coveralls": "~1.0",
Expand Down
8 changes: 8 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
parameters:
level: max

paths:
- test/types/

fileExtensions:
- php
6 changes: 3 additions & 3 deletions src/React/Promise.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Rx\React;

use React\Promise\CancellablePromiseInterface;
use React\Promise\Promise as ReactPromise;
use React\Promise\PromiseInterface;
use Rx\Disposable\CallbackDisposable;
Expand All @@ -11,6 +10,7 @@
use Rx\Observable\AnonymousObservable;
use Rx\Subject\AsyncSubject;
use React\Promise\Deferred;
use Throwable;

final class Promise
{
Expand All @@ -32,7 +32,7 @@ public static function resolved($value): ReactPromise
public static function rejected($exception): ReactPromise
{
$d = new Deferred();
$d->reject($exception);
$d->reject($exception instanceof Throwable ? $exception : new RejectedPromiseException($exception));
return $d->promise();
}

Expand Down Expand Up @@ -94,7 +94,7 @@ function ($error) use ($subject) {
$disp = $subject->subscribe($observer);
return new CallbackDisposable(function () use ($p, $disp) {
$disp->dispose();
if ($p instanceof CancellablePromiseInterface) {
if (\method_exists($p, 'cancel')) {
$p->cancel();
}
});
Expand Down
2 changes: 1 addition & 1 deletion test/Rx/Functional/Promise/FromPromiseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function () {
*/
public function from_promise_failure()
{
$p = \React\Promise\reject('error');
$p = \React\Promise\reject(new RejectedPromiseException('error'));

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

Expand Down

0 comments on commit dbb2364

Please sign in to comment.