Sleep before first reconnect attempt
This commit is contained in:
parent
530e08b9ee
commit
010bb6a102
@ -6,6 +6,7 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/jpillora/backoff"
|
"github.com/jpillora/backoff"
|
||||||
)
|
)
|
||||||
@ -54,6 +55,8 @@ func NewClient(nick, username string) *Client {
|
|||||||
reconnect: make(chan struct{}),
|
reconnect: make(chan struct{}),
|
||||||
recvBuf: make([]byte, 0, 4096),
|
recvBuf: make([]byte, 0, 4096),
|
||||||
backoff: &backoff.Backoff{
|
backoff: &backoff.Backoff{
|
||||||
|
Min: 500 * time.Millisecond,
|
||||||
|
Max: 30 * time.Second,
|
||||||
Jitter: true,
|
Jitter: true,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -79,6 +79,7 @@ func (c *Client) run() {
|
|||||||
c.sendRecv.Wait()
|
c.sendRecv.Wait()
|
||||||
c.reconnect = make(chan struct{})
|
c.reconnect = make(chan struct{})
|
||||||
|
|
||||||
|
time.Sleep(c.backoff.Duration())
|
||||||
c.tryConnect()
|
c.tryConnect()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user