GoCollections/util/time/tick.go

26 lines
378 B
Go
Raw Normal View History

2023-04-26 17:15:33 +08:00
package time
import (
"time"
unsafe2 "unsafe"
"github.com/tursom/GoCollections/unsafe"
)
type Ticker struct {
time.Ticker
}
func NewTicker(d Duration) *Ticker {
return &Ticker{*time.NewTicker(d)}
}
func (t *Ticker) Stop() {
t.Ticker.Stop()
close(*unsafe.ForceCast[chan time.Time](unsafe2.Pointer(&t.C)))
}
func Tick(d Duration) <-chan Time {
return time.Tick(d)
}