From 32b2049179e1cc060700c4f609cb4214644ac232 Mon Sep 17 00:00:00 2001 From: Keuin Date: Thu, 1 Jun 2023 21:55:56 +0800 Subject: Cool down before restarting from errors. --- common/cooldown.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 common/cooldown.go (limited to 'common/cooldown.go') 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)) +} -- cgit v1.2.3