forked from cerc-io/plugeth
9e6a1c3834
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. |
||
---|---|---|
.. | ||
discover | ||
dnsdisc | ||
enode | ||
enr | ||
msgrate | ||
nat | ||
netutil | ||
nodestate | ||
rlpx | ||
simulations | ||
tracker | ||
dial_test.go | ||
dial.go | ||
message_test.go | ||
message.go | ||
metrics.go | ||
peer_error.go | ||
peer_test.go | ||
peer.go | ||
protocol.go | ||
server_test.go | ||
server.go | ||
transport_test.go | ||
transport.go | ||
util_test.go | ||
util.go |