summaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorKeuin <[email protected]>2023-06-01 21:55:56 +0800
committerKeuin <[email protected]>2023-06-01 21:55:56 +0800
commit32b2049179e1cc060700c4f609cb4214644ac232 (patch)
tree93021774381fb8d95545b2796216aa0890f720d1 /common
parent6c3c988bae6f8a78afd3503743106395792ee2b0 (diff)
Cool down before restarting from errors.restart-cooldown
Diffstat (limited to 'common')
-rw-r--r--common/cooldown.go18
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))
+}