From 013740656627441ed59686272857b758c756c428 Mon Sep 17 00:00:00 2001 From: Joe Dixon Date: Fri, 24 Nov 2023 11:58:20 +0000 Subject: [PATCH] wip --- src/Channels/Channel.php | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/Channels/Channel.php b/src/Channels/Channel.php index f83df134..c31cd351 100644 --- a/src/Channels/Channel.php +++ b/src/Channels/Channel.php @@ -7,6 +7,7 @@ use Laravel\Reverb\Contracts\ChannelConnectionManager; use Laravel\Reverb\Contracts\Connection; use Laravel\Reverb\Output; +use React\Promise\Promise; class Channel { @@ -90,22 +91,24 @@ public function broadcast(array $payload, Connection $except = null): void $chunks = array_chunk($this->connections(), 100); foreach ($chunks as $connections) { - foreach ($connections as $connection) { - if ($except && $except->id() === $connection->connection()->id()) { - break; - } - - if (isset($payload['except']) && $payload['except'] === $connection->connection()->id()) { - break; - } - + new Promise(function ($resolve, $reject) use ($connections, $message, $except) { try { - $connection->send($message); + foreach ($connections as $connection) { + if ($except && $except->id() === $connection->connection()->id()) { + break; + } + + if (isset($payload['except']) && $payload['except'] === $connection->connection()->id()) { + break; + } + + $connection->send($message); + $resolve(); + } } catch (Exception $e) { - // Output::error('Broadcasting to '.$connection->id().' resulted in an error'); - // Output::info($e->getMessage()); - } - } + $reject($e); + } + }); } }