Describe the bug
The timer package's documentation does not accurately describe the actual behavior of the timer.
Setup
N/A
To Reproduce
t := timer.New(5 * time.Second)
t.Start()
t.Start() // According to documentation, this second start should have no effect
time.Sleep(time.Second + delta) // Just for demo purposes
fmt.Println(t.Timeout) // 3 * time.Second
Source Code
timer.startStop fires off a StartStopMsg message which in turn causes timer.Update to enqueue timer.tick. timer.tick in turn enqueues TickMsg. timer.Update assumes each tick is fired at exact intervals; therefore, calling timer.tick multiple times artificially speeds up the timer.
CS
Expected behavior
See documentation, which states calling timer.Start multiple times will have no effect. This is the expected behavior for a normal developer, but is not what actually happens.
A suggested fix will be to record the time of the last time a TickMsg message has been processed in timer.Update and subtract the duration (recommended in any case), or do not issue a StartStopMsg when timer.running matches the startStop input.
Screenshots
N/A
Additional context
The example suggested reset functionality as described in the example CS is also inaccurate. This assumes the timer is already in the run state and does nothing if the timer has already stopped.
Describe the bug
The timer package's documentation does not accurately describe the actual behavior of the timer.
Setup
N/A
To Reproduce
Source Code
timer.startStopfires off aStartStopMsgmessage which in turn causestimer.Updateto enqueuetimer.tick.timer.tickin turn enqueuesTickMsg.timer.Updateassumes each tick is fired at exact intervals; therefore, callingtimer.tickmultiple times artificially speeds up the timer.CS
Expected behavior
See documentation, which states calling
timer.Startmultiple times will have no effect. This is the expected behavior for a normal developer, but is not what actually happens.A suggested fix will be to record the time of the last time a
TickMsgmessage has been processed intimer.Updateand subtract the duration (recommended in any case), or do not issue aStartStopMsgwhentimer.runningmatches thestartStopinput.Screenshots
N/A
Additional context
The example suggested
resetfunctionality as described in the example CS is also inaccurate. This assumes the timer is already in the run state and does nothing if the timer has already stopped.