jonboulle / clockwork

a fake clock for golang
Apache License 2.0
625 stars 57 forks source link

Add a reset function to the ticker #54

Closed krasi-georgiev closed 1 year ago

krasi-georgiev commented 1 year ago

to allow a code like this

t := s.clock.NewTicker(s.config.InitialDelay)
var resetOnce sync.Once
defer t.Stop()
for {
    select {
    case <-s.newSlotCh:
        t.Reset(s.config.InitialDelay)
    case <-t.Chan()():
        resetOnce.Do(func() { t.Reset(s.config.PeriodicDelay) })
DPJacques commented 1 year ago

Ticker already implements reset:

Can you add a little detail about what you are looking for that is different from the current state?

krasi-georgiev commented 1 year ago

ooh, maybe the one that I am importing is an older version.

DPJacques commented 1 year ago

The version 3.0.0 doesn't have it yet. I am going to push a few more changes out before asking about bumping the version to 4.0.0.