Skip to content

Commit e519033

Browse files
authored
Merge pull request #460 from blinklabs-io/fix/keepalive-start
fix: send initial keep-alive immediately after start
2 parents d555908 + 1b331ab commit e519033

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

protocol/keepalive/client.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,21 @@ func NewClient(protoOptions protocol.ProtocolOptions, cfg *Config) *Client {
7373
func (c *Client) Start() {
7474
c.onceStart.Do(func() {
7575
c.Protocol.Start()
76-
c.startTimer()
76+
c.sendKeepAlive()
7777
})
7878
}
7979

80+
func (c *Client) sendKeepAlive() {
81+
msg := NewMsgKeepAlive(c.config.Cookie)
82+
if err := c.SendMessage(msg); err != nil {
83+
c.SendError(err)
84+
}
85+
// Reschedule timer
86+
c.startTimer()
87+
}
88+
8089
func (c *Client) startTimer() {
81-
c.timer = time.AfterFunc(c.config.Period, func() {
82-
msg := NewMsgKeepAlive(c.config.Cookie)
83-
if err := c.SendMessage(msg); err != nil {
84-
c.SendError(err)
85-
}
86-
})
90+
c.timer = time.AfterFunc(c.config.Period, c.sendKeepAlive)
8791
}
8892

8993
func (c *Client) messageHandler(msg protocol.Message) error {

0 commit comments

Comments
 (0)