timedqueue

package
v0.0.0-...-1974178 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2021 License: Apache-2.0, BSD-2-Clause Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

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

type ShutdownFlag = bitmask.BitMask

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 New

func New() (queue *TimedQueue)

New is the constructor for the TimedQueue.

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.

Jump to

Keyboard shortcuts

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