summaryrefslogtreecommitdiff
path: root/common/cooldown.go
blob: 75da6fdd2a0f36c541ddc77280e4b9d9ffaca165 (plain)
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))
}