[🚀] v0.12.21

This commit is contained in:
2025-02-27 15:00:51 +08:00
parent 3e5f407402
commit 388efae2ca
7 changed files with 141 additions and 135 deletions

View File

@ -21,11 +21,14 @@ type ticker struct {
f func()
}
func New(d time.Duration) Ticker {
ctx, cancelFunc := context.WithCancel(context.Background())
func New(d time.Duration, ctx ...context.Context) Ticker {
if len(ctx) < 1 {
ctx = append(ctx, context.Background())
}
c, cancelFunc := context.WithCancel(ctx[0])
return &ticker{
ticker: time.NewTicker(d),
ctx: ctx,
ctx: c,
cancel: cancelFunc,
}
}