From c3ca98e1b35123f226c7f4c596b5dee78caa4223 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 14:38:42 +0200 Subject: Adding upstream version 0.11.0. Signed-off-by: Daniel Baumann --- .../src/Multiple/ConnectionManagerConcurrent.php | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 vendor/clue/connection-manager-extra/src/Multiple/ConnectionManagerConcurrent.php (limited to 'vendor/clue/connection-manager-extra/src/Multiple/ConnectionManagerConcurrent.php') diff --git a/vendor/clue/connection-manager-extra/src/Multiple/ConnectionManagerConcurrent.php b/vendor/clue/connection-manager-extra/src/Multiple/ConnectionManagerConcurrent.php new file mode 100644 index 0000000..c1eb9cf --- /dev/null +++ b/vendor/clue/connection-manager-extra/src/Multiple/ConnectionManagerConcurrent.php @@ -0,0 +1,36 @@ +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) { + $promise->cancel(); + } + + // if promise resolves despite cancellation, immediately close stream + $promise->then(function ($stream) use ($conn) { + if ($stream !== $conn) { + $stream->close(); + } + }); + } + return $conn; + }); + } +} -- cgit v1.2.3