github.com/tursom/GoCollections@v0.3.10/util/time/tick.go (about) 1 package time 2 3 import ( 4 "time" 5 unsafe2 "unsafe" 6 7 "github.com/tursom/GoCollections/unsafe" 8 ) 9 10 type Ticker struct { 11 time.Ticker 12 } 13 14 func NewTicker(d Duration) *Ticker { 15 return &Ticker{*time.NewTicker(d)} 16 } 17 18 func (t *Ticker) Stop() { 19 t.Ticker.Stop() 20 close(*unsafe.ForceCast[chan time.Time](unsafe2.Pointer(&t.C))) 21 } 22 23 func Tick(d Duration) <-chan Time { 24 return time.Tick(d) 25 }