queue

package module
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Jun 13, 2020 License: MIT Imports: 3 Imported by: 0

README

queue

This is a FIFO queue for Go based on container/list.

Features
  • first in first out -- of course ;)
  • goroutine safe
  • both: blocking and non-blocking reading
  • Close to release blocking
  • all data is still read on Close
Benchmarks
BenchmarkQueue_Push-12                	10000000	       122 ns/op	      48 B/op	       1 allocs/op
BenchmarkQueue_Pop-12                 	30000000	      42.3 ns/op	       0 B/op	       0 allocs/op
BenchmarkQueue_PopBlocking-12         	30000000	      42.8 ns/op	       0 B/op	       0 allocs/op
BenchmarkQueue_Push_PopBlocking-12    	10000000	       129 ns/op	      48 B/op	       1 allocs/op

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Queue

type Queue struct {
	// contains filtered or unexported fields
}

Queue is a basic FIFO queue.

func NewQueue

func NewQueue() *Queue

NewQueue returns a new FIFO queue.

func (*Queue) Clear added in v0.1.3

func (s *Queue) Clear()

Clear empties the buffer

func (*Queue) Close

func (s *Queue) Close() error

Close closes the queue. Use this to release all PopBlocking calls. The queue will be emptied before PopBlocking returns false.

func (*Queue) Has added in v0.1.5

func (s *Queue) Has(check func(elem interface{}) bool) bool

Has checks if an item in the list exists according to the given check function. This is not blocking. When it is done the element you are looking for could have been added.

func (*Queue) Len added in v0.1.2

func (s *Queue) Len() int

Len reports the current length of the queue.

func (*Queue) Next added in v0.1.1

func (s *Queue) Next() bool

Next blocks until an element is available or the queue is closed. Reports false if the queue has been emptied and is closed. Beware that if multiple goroutines read from the queue, Pop can return false after Next was true.

func (*Queue) Pop

func (s *Queue) Pop() (interface{}, bool)

Pop removes and returns a node from the queue. The bool value is false if the queue was empty.

func (*Queue) PopBlocking

func (s *Queue) PopBlocking() (interface{}, bool)

PopBlocking removes and returns a node from the queue. It blocks until an element is available or the queue is closed. The bool value is false if the queue has been emptied and was closed.

func (*Queue) Push

func (s *Queue) Push(n interface{}) error

Push adds a node to the queue. Will fail if the queue has been closed.

func (*Queue) PushUnique added in v0.1.5

func (s *Queue) PushUnique(n interface{}, existFunc func(elem interface{}) bool) (bool, error)

PushUnique adds a node to the queue if it does not exist already. The existence is checked with existFunc. Will fail if the queue has been closed.

func (*Queue) Wait added in v0.1.6

func (s *Queue) Wait()

Wait blocks if the queue is empty until an item is added or the queue is closed.

Jump to

Keyboard shortcuts

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