From eb459a11955c4e49a5d3b6960d928aa31f0e8324 Mon Sep 17 00:00:00 2001 From: Savio Resende Date: Thu, 28 Dec 2023 14:50:07 -0600 Subject: [PATCH] Test timeout enhancement --- src/Client.php | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/Client.php b/src/Client.php index d35b92d..304495f 100644 --- a/src/Client.php +++ b/src/Client.php @@ -181,6 +181,9 @@ protected function handleDisconnection(): void ); } + /** + * @throws TimeoutException|Exception + */ protected function handleClientConnection(): void { $this->client = new WsClient( @@ -196,11 +199,19 @@ protected function handleClientConnection(): void $this->handleListeners(); $this->connectionReady(); - while($message = $this->client->receive()) { - if (null === $this->onMessageCallback) { - continue; + try { + while ($message = $this->client->receive()) { + if (null === $this->onMessageCallback) { + continue; + } + call_user_func($this->onMessageCallback, $this, $message); } - call_user_func($this->onMessageCallback, $this, $message); + } catch (TimeoutException $e) { + if ($this->timeout !== -1) { + throw $e; + } + } catch (Exception $e) { + throw $e; } }