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

[ADDED] Getters for connection callbacks #1162

Merged
merged 1 commit into from Dec 14, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
50 changes: 50 additions & 0 deletions nats.go
Expand Up @@ -1285,6 +1285,16 @@ func (nc *Conn) SetDisconnectErrHandler(dcb ConnErrHandler) {
nc.Opts.DisconnectedErrCB = dcb
}

// DisconnectErrHandler will return the disconnect event handler.
func (nc *Conn) DisconnectErrHandler() ConnErrHandler {
if nc == nil {
return nil
}
nc.mu.Lock()
defer nc.mu.Unlock()
return nc.Opts.DisconnectedErrCB
}

// SetReconnectHandler will set the reconnect event handler.
func (nc *Conn) SetReconnectHandler(rcb ConnHandler) {
if nc == nil {
Expand All @@ -1295,6 +1305,16 @@ func (nc *Conn) SetReconnectHandler(rcb ConnHandler) {
nc.Opts.ReconnectedCB = rcb
}

// ReconnectHandler will return the reconnect event handler.
func (nc *Conn) ReconnectHandler() ConnHandler {
if nc == nil {
return nil
}
nc.mu.Lock()
defer nc.mu.Unlock()
return nc.Opts.ReconnectedCB
}

// SetDiscoveredServersHandler will set the discovered servers handler.
func (nc *Conn) SetDiscoveredServersHandler(dscb ConnHandler) {
if nc == nil {
Expand All @@ -1305,6 +1325,16 @@ func (nc *Conn) SetDiscoveredServersHandler(dscb ConnHandler) {
nc.Opts.DiscoveredServersCB = dscb
}

// DiscoveredServersHandler will return the discovered servers handler.
func (nc *Conn) DiscoveredServersHandler() ConnHandler {
if nc == nil {
return nil
}
nc.mu.Lock()
defer nc.mu.Unlock()
return nc.Opts.DiscoveredServersCB
}

// SetClosedHandler will set the closed event handler.
func (nc *Conn) SetClosedHandler(cb ConnHandler) {
if nc == nil {
Expand All @@ -1315,6 +1345,16 @@ func (nc *Conn) SetClosedHandler(cb ConnHandler) {
nc.Opts.ClosedCB = cb
}

// ClosedHandler will return the closed event handler.
func (nc *Conn) ClosedHandler() ConnHandler {
if nc == nil {
return nil
}
nc.mu.Lock()
defer nc.mu.Unlock()
return nc.Opts.ClosedCB
}

// SetErrorHandler will set the async error handler.
func (nc *Conn) SetErrorHandler(cb ErrHandler) {
if nc == nil {
Expand All @@ -1325,6 +1365,16 @@ func (nc *Conn) SetErrorHandler(cb ErrHandler) {
nc.Opts.AsyncErrorCB = cb
}

// ErrorHandler will return the async error handler.
func (nc *Conn) ErrorHandler() ErrHandler {
if nc == nil {
return nil
}
nc.mu.Lock()
defer nc.mu.Unlock()
return nc.Opts.AsyncErrorCB
}

// Process the url string argument to Connect.
// Return an array of urls, even if only one.
func processUrlString(url string) []string {
Expand Down