1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
package common import "time" type CoolDown struct { MinInterval time.Duration lastTicked time.Time } func (c *CoolDown) Tick() { defer func() { c.lastTicked = time.Now() }() if c.lastTicked.IsZero() { return } time.Sleep(time.Now().Sub(c.lastTicked)) }