plugeth/common/mclock
Felix Lange 9e6a1c3834
common/mclock: add Alarm (#26333)
Alarm is a timer utility that simplifies code where a timer needs to be rescheduled over
and over. Doing this can be tricky with time.Timer or time.AfterFunc because the channel
requires draining in some cases.

Alarm is optimized for use cases where items are tracked in a heap according to their expiry
time, and a goroutine with a for/select loop wants to be woken up whenever the next item expires.
In this application, the timer needs to be rescheduled when an item is added or removed
from the heap. Using a timer naively, these updates will always require synchronization
with the global runtime timer datastructure to update the timer using Reset. Alarm avoids
this by tracking the next expiry time and only modifies the timer if it would need to fire earlier
than already scheduled.

As an example use, I have converted p2p.dialScheduler to use Alarm instead of AfterFunc.
2023-01-03 12:10:48 +01:00
..
alarm_test.go common/mclock: add Alarm (#26333) 2023-01-03 12:10:48 +01:00
alarm.go common/mclock: add Alarm (#26333) 2023-01-03 12:10:48 +01:00
mclock.go common/mclock: remove dependency on github.com/aristanetworks/goarista (#22211) 2021-01-22 20:15:27 +01:00
mclock.s common/mclock: remove dependency on github.com/aristanetworks/goarista (#22211) 2021-01-22 20:15:27 +01:00
simclock_test.go all: update license headers and AUTHORS from git history (#24947) 2022-05-24 20:39:40 +02:00
simclock.go all: use AbsTime.Add instead of conversion (#25417) 2022-07-29 18:23:30 +02:00