Skip to content

Commit

Permalink
Send event when ditto ping stops failing
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Sep 27, 2023
1 parent 6c98afb commit e6f9c36
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions libgm/longpoll.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,18 @@ const phoneNotRespondingTimeout = 30 * time.Second

func (c *Client) doDittoPinger(log *zerolog.Logger, dittoPing <-chan struct{}, stopPinger <-chan struct{}) {
notResponding := false
pingFailed := false
exit := false
onRespond := func() {
if notResponding {
log.Debug().Msg("Ditto ping succeeded, phone is back online")
c.triggerEvent(&events.PhoneRespondingAgain{})
notResponding = false
pingFailed = false
} else if pingFailed {
// TODO separate event?
c.triggerEvent(&events.PhoneRespondingAgain{})
pingFailed = false
}
}
doPing := func() {
Expand All @@ -40,6 +46,7 @@ func (c *Client) doDittoPinger(log *zerolog.Logger, dittoPing <-chan struct{}, s
c.triggerEvent(&events.PingFailed{
Error: fmt.Errorf("failed to notify ditto activity: %w", err),
})
pingFailed = true
return
}
select {
Expand Down

0 comments on commit e6f9c36

Please sign in to comment.