From 94a11e552b50a389a4e3a6b5fe7bdea4ce7097a4 Mon Sep 17 00:00:00 2001 From: Anhgelus Morhtuuzh Date: Thu, 22 Jan 2026 15:50:28 +0100 Subject: refactor(main): remove old gokord from start --- common/timer.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 common/timer.go (limited to 'common/timer.go') 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 +} -- cgit v1.2.3