Documentation ¶
Overview ¶
Package deadlinequeue implements a deadline queue. It provides a QueueItem interface which can be used to define an item wnich can enqueued to and dequeued from the deadline queue. It also provides an Item structure which implements a sample queue item. The deadline queue provides an Enqueue call which can be used to enqueue a queue item with a deadline indicating whien the item should be dequeued, and a Dequeue call which is a blocking call which returns the first item in the queue when its deadline expires.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DeadlineQueue ¶
type DeadlineQueue interface { // Enqueue is used to enqueue a queue item with a deadline Enqueue(qi QueueItem, deadline time.Time) // Dequeue is a blocking call to wait for the next queue item // whose deadline expires. Dequeue(stopChan <-chan struct{}) QueueItem }
DeadlineQueue defines the interface of a deadline queue implementation. Items with a deadline can be enqueued, and when the deadline expires, dequeue operation will return back the item.
func NewDeadlineQueue ¶
func NewDeadlineQueue(mtx *QueueMetrics) DeadlineQueue
NewDeadlineQueue returns a deadline queue object.
type Item ¶
type Item struct {
// contains filtered or unexported fields
}
Item implements a queue item storing a string identifier.
func (*Item) IsScheduled ¶
func (i *Item) IsScheduled() bool
func (*Item) SetDeadline ¶
type QueueItem ¶
type QueueItem interface { // IsScheduled returns true if the queue item is enqueued in the deadline queue. IsScheduled() bool // Deadline returns the deadline at which the queue item will be dequeued. Deadline() time.Time // SetDeadline sets the time at which the queue item will be dequeued. SetDeadline(deadline time.Time) // SetIndex sets the index of the queue item in the queue. SetIndex(index int) // Index fetches the index of the queue item in the queue. Index() int }
QueueItem is the interface an item enqueued in the deadline queue needs to support.
type QueueMetrics ¶
type QueueMetrics struct {
// contains filtered or unexported fields
}
QueueMetrics contains all counters to track queue metrics
func NewQueueMetrics ¶
func NewQueueMetrics(scope tally.Scope) *QueueMetrics
NewQueueMetrics returns a new QueueMetrics struct.