queue

package
v0.0.0-...-aa2a11b Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2019 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package queue implements different kinds of queues

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Base

type Base interface {
	// Next item in the Queue, this function blocks until the next item is available.
	// It returns <nil> to all callers when Destroy() is called.
	Next() interface{}

	IsEmpty() bool

	// Destroy the queue
	Destroy()
}

Base interface for Queue

type JIT

type JIT interface {
	Base

	// Add an Item to the JIT Queue, will be returned by Next() at item.Time()
	Add(item JITItem)

	// Schedule an Item to the JIT Queue, will be returned by Next() at time
	Schedule(i interface{}, time time.Time)
}

JIT is a just-in-time implementation of the Queue. It allows setting a time for each item in the queue. The item will be returned by Next() immediately after this time.

func NewJIT

func NewJIT() JIT

NewJIT returns a new JIT Queue (see JIT interface)

type JITItem

type JITItem interface {
	Time() time.Time
}

JITItem has a Time()

type Schedule

type Schedule interface {
	Base

	// Add an Item to the Schedule, queued to be returned at item.Time(),
	// this func returns the conflicts based on item.Time() and item.Duration()
	Add(item ScheduleItem) []ScheduleItem

	// Conflicts based on time and duration
	Conflicts(time time.Time, duration time.Duration) []ScheduleItem

	// Conflicts based on timestamp and duration
	ConflictsForTimestamp(timestamp int64, duration time.Duration) []ScheduleItem

	// Schedule an item at the given time, with the given duration
	// this func returns the conflicts based on item time and duration
	Schedule(i interface{}, time time.Time, duration time.Duration) []ScheduleItem

	// Schedule an item at the given time+timestamp, with the given duration
	// this func returns the conflicts based on item timestamp and duration
	ScheduleWithTimestamp(i interface{}, time time.Time, timestamp int64, duration time.Duration) []ScheduleItem

	// ScheduleASAP schedules an item as soon as possible, given its duration and considering the existing Schedule
	// this func returns the time at which the item is scheduled
	ScheduleASAP(i interface{}, duration time.Duration) time.Time
}

Schedule is an extension of the JIT Queue that allows setting a duration next to the time of an item. This allows to calculate the conflicts that an item has

func NewSchedule

func NewSchedule() Schedule

NewSchedule returns a new Schedule (see Schedule interface)

type ScheduleItem

type ScheduleItem interface {
	JITItem
	Duration() time.Duration
}

ScheduleItem has a Time() and Duration()

type ScheduleItemWithTimestamp

type ScheduleItemWithTimestamp interface {
	Timestamp() int64
	Duration() time.Duration
}

ScheduleItemWithTimestamp has a Timestamp() and Duration()

type Simple

type Simple interface {
	Base

	// Add an item to the Queue
	Add(interface{})
}

Simple Queue implementation

func NewSimple

func NewSimple() Simple

NewSimple returns a new Simple Queue

Jump to

Keyboard shortcuts

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