-
Notifications
You must be signed in to change notification settings - Fork 352
Description
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.SecondSource 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.
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.