Browse Source

add IsReconnecting and IsActive methods

pull/604/head
Anton Kaliaev 7 years ago
parent
commit
54903adeff
No known key found for this signature in database GPG Key ID: 7B6881D965918214
1 changed files with 17 additions and 0 deletions
  1. +17
    -0
      rpc/lib/client/ws_client.go

+ 17
- 0
rpc/lib/client/ws_client.go View File

@ -54,6 +54,8 @@ type WSClient struct {
reconnectAfter chan error // reconnect requests
receiveRoutineQuit chan struct{} // a way for receiveRoutine to close writeRoutine
reconnecting bool
wg sync.WaitGroup
mtx sync.RWMutex
}
@ -115,6 +117,16 @@ func (c *WSClient) Stop() bool {
return success
}
// IsReconnecting returns true if the client is reconnecting right now.
func (c *WSClient) IsReconnecting() bool {
return c.reconnecting
}
// IsActive returns true if the client is running and not reconnecting.
func (c *WSClient) IsActive() bool {
return c.IsRunning() && !c.IsReconnecting()
}
// Send asynchronously sends the given RPCRequest to the server. Results will
// be available on ResultsCh, errors, if any, on ErrorsCh.
func (c *WSClient) Send(ctx context.Context, request types.RPCRequest) error {
@ -170,6 +182,11 @@ func (c *WSClient) dial() error {
func (c *WSClient) reconnect() error {
attempt := 0
c.reconnecting = true
defer func() {
c.reconnecting = false
}()
for {
c.Logger.Info("reconnecting", "attempt", attempt+1)


Loading…
Cancel
Save