github.com/jxskiss/gopkg/v2@v2.14.9-0.20240514120614-899f3e7952b4/internal/functicker/ticker.go (about) 1 package functicker 2 3 import "time" 4 5 type Ticker struct { 6 t *time.Ticker 7 } 8 9 func New(d time.Duration, f func()) *Ticker { 10 timer := time.AfterFunc(time.Hour, f) 11 timer.Stop() 12 ticker := (*time.Ticker)(timer) 13 ticker.Reset(d) 14 return &Ticker{t: ticker} 15 } 16 17 func (t *Ticker) Stop() { 18 t.t.Stop() 19 } 20 21 func (t *Ticker) Reset(d time.Duration) { 22 t.t.Reset(d) 23 }