Skip to content

Commit 4bf56e6

Browse files
committed
Added method that exposes connection state; whether it is closed or not.
1 parent c8749e5 commit 4bf56e6

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

connection.go

+5
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,8 @@ func (conn *Conn) Close() error {
8888
conn.closeConnectionToManagerCh <- struct{}{}
8989
return conn.connectionManager.Close()
9090
}
91+
92+
// IsClosed returns whether the connection is closed or not
93+
func (conn *Conn) IsClosed() bool {
94+
return conn.connectionManager.IsClosed()
95+
}

internal/connectionmanager/connection_manager.go

+8
Original file line numberDiff line numberDiff line change
@@ -171,3 +171,11 @@ func (connManager *ConnectionManager) reconnect() error {
171171
connManager.connection = conn
172172
return nil
173173
}
174+
175+
// IsClosed checks if the connection is closed
176+
func (connManager *ConnectionManager) IsClosed() bool {
177+
connManager.connectionMu.Lock()
178+
defer connManager.connectionMu.Unlock()
179+
180+
return connManager.connection.IsClosed()
181+
}

0 commit comments

Comments
 (0)