Skip to content

Commit

Permalink
Fix connect() to work with external component
Browse files Browse the repository at this point in the history
  • Loading branch information
davej-improbable committed Sep 4, 2020
1 parent ac5b066 commit ddb8c5a
Showing 1 changed file with 19 additions and 14 deletions.
33 changes: 19 additions & 14 deletions stream_manager.go
Expand Up @@ -113,22 +113,27 @@ func (sm *StreamManager) Stop() {
}

func (sm *StreamManager) connect() error {
if sm.client != nil {
if c, ok := sm.client.(*Client); ok {
if c.CurrentState.getState() == StateDisconnected {
sm.Metrics = initMetrics()
err := c.Connect()
if err != nil {
return err
}
if sm.PostConnect != nil {
sm.PostConnect(sm.client)
}
return nil
}
if sm.client == nil {
return errors.New("client is not set")
}

if c, ok := sm.client.(*Client); ok {
if c.CurrentState.getState() != StateDisconnected {
return errors.New("client is not disconnected")
}
}
return errors.New("client is not disconnected")

sm.Metrics = initMetrics()

if err := sm.client.Connect(); err != nil {
return err
}

if sm.PostConnect != nil {
sm.PostConnect(sm.client)
}

return nil
}

// resume manages the reconnection loop and apply the define backoff to avoid overloading the server.
Expand Down

0 comments on commit ddb8c5a

Please sign in to comment.