Simplify
This commit is contained in:
parent
c3cd6e41cd
commit
1e509e4f6e
1 changed files with 7 additions and 12 deletions
|
|
@ -182,17 +182,18 @@ func NewWarpWS(ctx context.Context, uri, user, password string, meterIndex uint)
|
|||
}
|
||||
}
|
||||
|
||||
go w.run(uri, user, password, ctx)
|
||||
go w.run(ctx, uri, user, password)
|
||||
|
||||
return w, nil
|
||||
}
|
||||
|
||||
func (w *WarpWS) run(uri, user, pass string, ctx context.Context) {
|
||||
bo := backoff.NewExponentialBackOff(backoff.WithMaxElapsedTime(0))
|
||||
bo.MaxInterval = 30 * time.Second
|
||||
func (w *WarpWS) run(ctx context.Context, uri, user, pass string) {
|
||||
bo := backoff.NewExponentialBackOff(
|
||||
backoff.WithMaxInterval(30*time.Second),
|
||||
backoff.WithMaxElapsedTime(0))
|
||||
|
||||
for ctx.Err() == nil {
|
||||
w.log.DEBUG.Printf("ws connecting to %s …", uri)
|
||||
w.log.DEBUG.Printf("ws connecting to %s", uri)
|
||||
|
||||
conn, resp, err := dialWebsocket(ctx, uri, user, pass)
|
||||
if err != nil {
|
||||
|
|
@ -212,16 +213,10 @@ func (w *WarpWS) run(uri, user, pass string, ctx context.Context) {
|
|||
}
|
||||
}
|
||||
|
||||
if ctx.Err() != nil {
|
||||
return
|
||||
}
|
||||
d := bo.NextBackOff()
|
||||
w.log.DEBUG.Printf("ws reconnecting to %s in %v", uri, d)
|
||||
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
case <-time.After(d):
|
||||
case <-time.After(bo.NextBackOff()):
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue