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

Forward compatibility with upcoming Promise v3 #34

Merged
merged 2 commits into from
Aug 30, 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
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
},
"require": {
"php": ">=5.3",
"react/socket": "^1.9",
"react/event-loop": "^1.2",
"react/promise": "^2.1 || ^1.2.1",
"react/promise-timer": "^1.1"
"react/promise": "^3 || ^2.1 || ^1.2.1",
"react/promise-timer": "^1.9",
"react/socket": "^1.12"
},
"require-dev": {
"phpunit/phpunit": "^9.3 || ^5.7 || ^4.8"
Expand Down
4 changes: 2 additions & 2 deletions src/ConnectionManagerRepeat.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use InvalidArgumentException;
use Exception;
use React\Promise\Promise;
use React\Promise\CancellablePromiseInterface;
use React\Promise\PromiseInterface;

class ConnectionManagerRepeat implements ConnectorInterface
{
Expand Down Expand Up @@ -44,7 +44,7 @@ public function connect($uri)
$tries = 0;
$reject(new \RuntimeException('Cancelled'));

if ($pending instanceof CancellablePromiseInterface) {
if ($pending instanceof PromiseInterface && \method_exists($pending, 'cancel')) {
$pending->cancel();
}
});
Expand Down
6 changes: 2 additions & 4 deletions src/Multiple/ConnectionManagerConcurrent.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,22 @@

namespace ConnectionManager\Extra\Multiple;

use ConnectionManager\Extra\Multiple\ConnectionManagerConsecutive;
use React\Promise;
use React\Promise\CancellablePromiseInterface;
use React\Promise\PromiseInterface;

class ConnectionManagerConcurrent extends ConnectionManagerConsecutive
{
public function connect($uri)
{
$all = array();
foreach ($this->managers as $connector) {
/* @var $connection Connector */
$all []= $connector->connect($uri);
}
return Promise\any($all)->then(function ($conn) use ($all) {
// a connection attempt succeeded
// => cancel all pending connection attempts
foreach ($all as $promise) {
if ($promise instanceof CancellablePromiseInterface) {
if ($promise instanceof PromiseInterface && \method_exists($promise, 'cancel')) {
$promise->cancel();
}

Expand Down
6 changes: 3 additions & 3 deletions src/Multiple/ConnectionManagerConsecutive.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

namespace ConnectionManager\Extra\Multiple;

use React\Socket\ConnectorInterface;
use React\Promise;
use React\Promise\PromiseInterface;
use React\Socket\ConnectorInterface;
use UnderflowException;
use React\Promise\CancellablePromiseInterface;

class ConnectionManagerConsecutive implements ConnectorInterface
{
Expand Down Expand Up @@ -54,7 +54,7 @@ public function tryConnection(array $managers, $uri)
$managers = array();
$reject(new \RuntimeException('Cancelled'));

if ($pending instanceof CancellablePromiseInterface) {
if ($pending instanceof PromiseInterface && \method_exists($pending, 'cancel')) {
$pending->cancel();
}
});
Expand Down