diff options
author | Keuin <[email protected]> | 2023-06-01 21:55:56 +0800 |
---|---|---|
committer | Keuin <[email protected]> | 2023-07-29 20:16:08 +0800 |
commit | 0da1d6d8107f8619aa53f80e14b2cc1bc10ce2ae (patch) | |
tree | 8d9cf06a9c900acdc3467306f22a81c3f46170a4 /common/cooldown.go | |
parent | 49082656b79cea1d5ea21fe92564eaddd9b5843a (diff) |
Cool down before restarting from errors.
Diffstat (limited to 'common/cooldown.go')
-rw-r--r-- | common/cooldown.go | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/common/cooldown.go b/common/cooldown.go new file mode 100644 index 0000000..75da6fd --- /dev/null +++ b/common/cooldown.go @@ -0,0 +1,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)) +} |