Store the backoff in the client struct
This commit is contained in:
parent
c22b7d2a1d
commit
83aef5df7b
2 changed files with 7 additions and 7 deletions
|
@ -7,8 +7,6 @@ import (
|
|||
"net"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/khlieng/dispatch/Godeps/_workspace/src/github.com/jpillora/backoff"
|
||||
)
|
||||
|
||||
func (c *Client) Connect(address string) {
|
||||
|
@ -84,10 +82,6 @@ func (c *Client) connect() error {
|
|||
}
|
||||
|
||||
func (c *Client) tryConnect() {
|
||||
b := &backoff.Backoff{
|
||||
Jitter: true,
|
||||
}
|
||||
|
||||
for {
|
||||
select {
|
||||
case <-c.quit:
|
||||
|
@ -98,10 +92,11 @@ func (c *Client) tryConnect() {
|
|||
|
||||
err := c.connect()
|
||||
if err == nil {
|
||||
c.backoff.Reset()
|
||||
return
|
||||
}
|
||||
|
||||
time.Sleep(b.Duration())
|
||||
time.Sleep(c.backoff.Duration())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue