queue

package
v1.7.9 Latest Latest
Warning

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

Go to latest
Published: Apr 14, 2018 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Item

type Item interface {
	Len() int
}

type Queue

type Queue interface {
	// Add an Item to the back of the queue
	// will return false if the queue is closed.
	// In that case the Item is dropped.
	Add(i Item) bool

	// Remove will remove a Item from the queue.
	// If false is returned, it either means 1) there were no items on the queue
	// or 2) the queue is closed.
	Remove() (Item, bool)

	// Close the queue and discard all entried in the queue
	// all goroutines in wait() will return
	Close()

	// CloseRemaining will close the queue and return all entried in the queue.
	// All goroutines in wait() will return
	CloseRemaining() []Item

	// Closed returns true if the queue has been closed
	// The call cannot guarantee that the queue hasn't been
	// closed while the function returns, so only "true" has a definite meaning.
	Closed() bool

	// Wait for a Item to be added or queue to be closed.
	// If there is items on the queue the first will
	// be returned immediately.
	// Will return "", false if the queue is closed.
	// Otherwise the return value of "remove" is returned.
	Wait() (Item, bool)

	// Cap returns the capacity (without allocations).
	Cap() int

	// Len returns the current length of the queue.
	Len() int

	// Size returns the current size of the queue in bytes.
	Size() int
}

Queue is an unbounded queue of Item. The queue is goroutine safe. Inspired by http://blog.dubbelboer.com/2015/04/25/go-faster-queue.html (MIT)

func New

func New(initialCapacity int) Queue

New ByteQueue returns a new Item queue with initial capacity.

Jump to

Keyboard shortcuts

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