time.Now() uses the wall-clock and therefore calling it twice, one
second apart, can produce quite different results (negative results but
also a difference greater than one second). Go doesn't expose a
monotonic clock, therefore, it's difficult to properly fix (but there is
https://github.com/gavv/monotime if we want a proper fix for
timer.Time()).
This workaround just discard any negative duration.
There are other places that incorrectly uses time.Now(). I can add a similar check or I can import monotime to properly fixes them.
time.Now()
uses the wall-clock and therefore calling it twice, one second apart, can produce quite different results (negative results but also a difference greater than one second). Go doesn't expose a monotonic clock, therefore, it's difficult to properly fix (but there is https://github.com/gavv/monotime if we want a proper fix fortimer.Time()
).This workaround just discard any negative duration.
There are other places that incorrectly uses
time.Now()
. I can add a similar check or I can importmonotime
to properly fixes them.