Skip to content

Commit

Permalink
[ADDED] Getters for connection callbacks (#1162)
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrpio authored Dec 14, 2022
1 parent 6c6add8 commit 95a7e50
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions nats.go
Original file line number Diff line number Diff line change
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

0 comments on commit 95a7e50

Please sign in to comment.