1
0
Fork 0
mirror of https://github.com/diamondburned/arikawa.git synced 2024-12-02 20:02:53 +00:00

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

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()