Closed gagern closed 1 year ago
Oh! I see this has AfterFunc
too. Can this get merged? Then #45 can be closed w/o merging.
@sagikazarmark could you tag a new release with these changes?
the old code (v0.3.0) leavings zombie go routines if .Stop()
wasn't called on a timer
Unfortunately this change seems to introduce some regressions. Waiting for those to be fixed.
In terms of features, the addition of
AfterFunc
is the main benefit here. Otherwise it addresses a number of bugs, mainly around out-of-order or duplicate delivery of events, as exposed by the various tests added by these changes.These changes merge the
sleeper
and thefakeTimer
task. Now afakeTimer
object is used to represent any future event on the timeline of a given fake clock. When the time advances to that point, a callback on thefakeTimer
gets called. This makes sending to a channel only one of many possible responses on expiry. Not using channels, but instead an internal callback that gets called with the clock's lock held, allows using the timer far more flexible. It is now also the basis of ticker and of theAfter
method. This change in general will do more things while holding the clock's lock, leading to more consistent behavior and less risk of data races.Basing
After
onTimer
instead of the other way round also allows clearing the future events when timers get stopped or reset. This in turn helpsBlockUntil
actually track active blockers, ignoring obsolete ones that used to exist in the past.This fixes https://github.com/jonboulle/clockwork/issues/42.