Help us shape the future of Go! Take the 2026 Go Developer Survey

queue

package module
v0.1.4 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2019 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) 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.

Jump to

Keyboard shortcuts

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