Gateway: Fixed unexpected ticker.Stop() blocking behavior

This commit is contained in:
diamondburned (Forefront) 2020-04-11 20:38:10 -07:00
parent 01e52334c6
commit 320e8a52f1
1 changed files with 13 additions and 1 deletions

View File

@ -69,7 +69,19 @@ func (p *Pacemaker) Stop() {
func (p *Pacemaker) start() error {
tick := time.NewTicker(p.Heartrate)
defer tick.Stop()
defer func() {
// Flush the ticker:
select {
case <-tick.C:
WSDebug("Flushed a tick.")
default:
WSDebug("No tick flushed.")
}
// Then close the ticker:
tick.Stop()
}()
// Echo at least once
p.Echo()