Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Added connection state check #196

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
8 changes: 8 additions & 0 deletions internal/connectionmanager/connection_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}