Documentation ¶
Overview ¶
Package actionqueue provides a timed event queue with expiry support.
Any event is added to the queue with two parameters, ActionTime and ExpireTime. The event will be fired upon ActionTime through the the NextEvent channel.
The caller may choose either to receive an event immediately, or at any time before it is expired. The queue takes care of the ExpireTime, and cancel expired events upon expiry.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Action ¶
type Action struct { Value interface{} ActionTime time.Time ExpireTime time.Time // contains filtered or unexported fields }
An Action is an event that fires after ActionTime, and expires if not handled before ExpireTime.
If ExpireTime is zero-value, the action never expires.
type Queue ¶
type Queue struct {
// contains filtered or unexported fields
}
A Queue stores actions and triggers actions on time.
func (*Queue) AddActionWithExpiry ¶
AddActionWithExpiry adds a new action with an expireTime.
An Action is an event that triggers after ActionTime, and expires if not handled before ExpireTime.
func (*Queue) Dump ¶
Dump returns a copy of upcoming actions, useful when saving to disk.
To restore the actions back to a queue, insert them one by one.
Note 1: The Queue MUST be stopped before dumping, or the function will panic.
Note 2: Only one goroutine may call Dump at the same time.
func (*Queue) NextAction ¶
NextAction returns a channel for upcoming actions.
To receive next action, use <-q.NextAction().
Subsquential calls to NextAction returns the same channel.