@@ -40,11 +40,13 @@ type RecConn struct {
|
|||||||
Proxy func(*http.Request) (*url.URL, error)
|
Proxy func(*http.Request) (*url.URL, error)
|
||||||
// Client TLS config to use on reconnect
|
// Client TLS config to use on reconnect
|
||||||
TLSClientConfig *tls.Config
|
TLSClientConfig *tls.Config
|
||||||
// SubscribeHandler fires after the connection successfully establish.
|
// SubscribeHandler fires after the connection successfully establish. Must be quick
|
||||||
SubscribeHandler func() error
|
SubscribeHandler func() error
|
||||||
// KeepAliveTimeout is an interval for sending ping/pong messages
|
// KeepAliveTimeout is an interval for sending ping/pong messages
|
||||||
// disabled if 0
|
// disabled if 0
|
||||||
KeepAliveTimeout time.Duration
|
KeepAliveTimeout time.Duration
|
||||||
|
// ReconnectHandler signals of reconnects for metrics. Must be quick
|
||||||
|
ReconnectHandler func()
|
||||||
// LogHandler handles all log messages
|
// LogHandler handles all log messages
|
||||||
LogHandler func(v LogValues)
|
LogHandler func(v LogValues)
|
||||||
// NonVerbose suppress connecting/reconnecting messages.
|
// NonVerbose suppress connecting/reconnecting messages.
|
||||||
@@ -76,9 +78,17 @@ type LogValues struct {
|
|||||||
Fatal bool
|
Fatal bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (rc *RecConn) handleReconnect() {
|
||||||
|
rc.mu.RLock()
|
||||||
|
handler := rc.ReconnectHandler
|
||||||
|
rc.mu.RUnlock()
|
||||||
|
handler()
|
||||||
|
}
|
||||||
|
|
||||||
// CloseAndReconnect will try to reconnect.
|
// CloseAndReconnect will try to reconnect.
|
||||||
func (rc *RecConn) CloseAndReconnect() {
|
func (rc *RecConn) CloseAndReconnect() {
|
||||||
rc.Close()
|
rc.Close()
|
||||||
|
rc.handleReconnect()
|
||||||
go rc.connect()
|
go rc.connect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user