From 39f2ea4e110f1602e359c711061b0ceb64e2e968 Mon Sep 17 00:00:00 2001 From: Christopher Vagnetoft Date: Fri, 1 Mar 2024 22:27:55 +0100 Subject: [PATCH] Fixed bug preventing client reconnecting --- src/CommandBusClient.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/CommandBusClient.php b/src/CommandBusClient.php index 262e993..3ac681c 100644 --- a/src/CommandBusClient.php +++ b/src/CommandBusClient.php @@ -71,6 +71,7 @@ class CommandBusClient implements CommandBusInterface $this->isReconnecting = true; $this->connector->connect($this->address)->then( function (DuplexStreamInterface $connection) { + $this->isReconnecting = false; $this->connection = $connection; $this->emit(self::EVENT_CONNECTED); $connection->on('error', function ($error) { @@ -79,14 +80,12 @@ class CommandBusClient implements CommandBusInterface if ($this->autoReconnect) { Loop::addTimer(1, $this->reconnect(...)); } - $this->isReconnecting = false; }); $connection->on('close', function () { $this->emit(self::EVENT_DISCONNECTED); if ($this->autoReconnect) { Loop::addTimer(1, $this->reconnect(...)); } - $this->isReconnecting = false; }); $connection->on('data', function ($data) use ($connection) { try { @@ -100,6 +99,7 @@ class CommandBusClient implements CommandBusInterface }); }, function (Throwable $e) { + $this->isReconnecting = false; $this->emit(self::EVENT_ERROR, [ $e->getMessage(), $e ]); Loop::addTimer(5, $this->reconnect(...)); }