aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
authorAnhgelus Morhtuuzh <william@herges.fr>2026-01-22 15:50:28 +0100
committerAnhgelus Morhtuuzh <william@herges.fr>2026-01-22 15:50:28 +0100
commit94a11e552b50a389a4e3a6b5fe7bdea4ce7097a4 (patch)
tree3342b8dadbd723fbf7e9f568e7944fe3a626f4df /common
parent42c25b54e169aeaf515522ba6103b1fe6db49be7 (diff)
refactor(main): remove old gokord from start
Diffstat (limited to 'common')
-rw-r--r--common/timer.go28
1 files changed, 28 insertions, 0 deletions
diff --git a/common/timer.go b/common/timer.go
new file mode 100644
index 0000000..553a8fd
--- /dev/null
+++ b/common/timer.go
@@ -0,0 +1,28 @@
+package common
+
+import (
+ "context"
+ "time"
+
+ "github.com/nyttikord/gokord/bot"
+)
+
+func NewTimer(ctx context.Context, d time.Duration, fn func(context.Context, context.CancelFunc)) context.CancelFunc {
+ ctx, cancel := context.WithCancel(ctx)
+ logger := bot.Logger(ctx).With("module", "timer")
+ ctx = bot.SetLogger(ctx, logger)
+ go func(ctx context.Context, d time.Duration) {
+ ticker := time.NewTicker(d)
+ fn(ctx, cancel)
+ for {
+ select {
+ case <-ticker.C:
+ fn(ctx, cancel)
+ case <-ctx.Done():
+ ticker.Stop()
+ return
+ }
+ }
+ }(ctx, d)
+ return cancel
+}