Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option func(queue *TimedQueue)
Option is the type for functional options of the TimedQueue.
func WithMaxSize ¶
WithMaxSize is an Option for the TimedQueue that allows to specify a maxSize of the queue.
type QueueElement ¶
type QueueElement struct { // Value represents the value of the queued element. Value interface{} // ScheduledTime represents the time at which the element is due. ScheduledTime time.Time // contains filtered or unexported fields }
QueueElement is an element in the TimedQueue. It.
func (*QueueElement) Cancel ¶
func (timedQueueElement *QueueElement) Cancel()
Cancel removed the given element from the queue and cancels its execution.
type ShutdownFlag ¶
ShutdownFlag defines the type of the optional shutdown flags.
const ( // CancelPendingElements defines a shutdown flag, that causes the queue to be emptied on shutdown. CancelPendingElements ShutdownFlag = 1 << iota // IgnorePendingTimeouts defines a shutdown flag, that makes the queue ignore the timeouts of the remaining queued // elements. Consecutive calls to Poll will immediately return these elements. IgnorePendingTimeouts // PanicOnModificationsAfterShutdown makes the queue panic instead of ignoring consecutive writes or modifications. PanicOnModificationsAfterShutdown )
type TimedQueue ¶
type TimedQueue struct {
// contains filtered or unexported fields
}
TimedQueue represents a queue, that holds values that will only be released at a given time. The corresponding Poll method waits for the element to be available before it returns its value and is therefore blocking.
func (*TimedQueue) Add ¶
func (t *TimedQueue) Add(value interface{}, scheduledTime time.Time) (addedElement *QueueElement)
Add inserts a new element into the queue that can be retrieved via Poll() at the specified time.
func (*TimedQueue) IsShutdown ¶
func (t *TimedQueue) IsShutdown() bool
IsShutdown returns true if this queue was shutdown.
func (*TimedQueue) Poll ¶
func (t *TimedQueue) Poll(waitIfEmpty bool) interface{}
Poll returns the first value of this queue. It waits for the scheduled time before returning and is therefore blocking. It returns nil if the queue is empty.
func (*TimedQueue) Shutdown ¶
func (t *TimedQueue) Shutdown(optionalShutdownFlags ...ShutdownFlag)
Shutdown terminates the queue. It accepts an optional list of shutdown flags that allows the caller to modify the shutdown behavior.
func (*TimedQueue) Size ¶
func (t *TimedQueue) Size() int
Size returns the amount of elements that are currently enqueued in this queue.