deadlinequeue

package
v0.0.0-...-a69e935 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 1, 2019 License: Apache-2.0 Imports: 4 Imported by: 2

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 NewItem

func NewItem(str string) *Item

NewItem returns a newly created Item.

func (*Item) Deadline

func (i *Item) Deadline() time.Time

func (*Item) GetString

func (dqi *Item) GetString() string

GetString fetches the string identifier stored in Item.

func (*Item) Index

func (i *Item) Index() int

func (*Item) IsScheduled

func (i *Item) IsScheduled() bool

func (*Item) SetDeadline

func (i *Item) SetDeadline(deadline time.Time)

func (*Item) SetIndex

func (i *Item) SetIndex(index int)

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL