[🚀] v0.12.21
This commit is contained in:
@ -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,
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user