From 4bf56e6808d4c61ab532bbaf27344bcd250b16e7 Mon Sep 17 00:00:00 2001 From: bdular Date: Wed, 27 Nov 2024 23:08:57 +0100 Subject: [PATCH] Added method that exposes connection state; whether it is closed or not. --- connection.go | 5 +++++ internal/connectionmanager/connection_manager.go | 8 ++++++++ 2 files changed, 13 insertions(+) diff --git a/connection.go b/connection.go index 4e14560..8d33a6b 100644 --- a/connection.go +++ b/connection.go @@ -88,3 +88,8 @@ func (conn *Conn) Close() error { conn.closeConnectionToManagerCh <- struct{}{} return conn.connectionManager.Close() } + +// IsClosed returns whether the connection is closed or not +func (conn *Conn) IsClosed() bool { + return conn.connectionManager.IsClosed() +} diff --git a/internal/connectionmanager/connection_manager.go b/internal/connectionmanager/connection_manager.go index 1967c46..4b9ef67 100644 --- a/internal/connectionmanager/connection_manager.go +++ b/internal/connectionmanager/connection_manager.go @@ -171,3 +171,11 @@ func (connManager *ConnectionManager) reconnect() error { connManager.connection = conn return nil } + +// IsClosed checks if the connection is closed +func (connManager *ConnectionManager) IsClosed() bool { + connManager.connectionMu.Lock() + defer connManager.connectionMu.Unlock() + + return connManager.connection.IsClosed() +}