queue

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2019 License: MIT Imports: 3 Imported by: 1

Documentation

Overview

Package queue provides queue-like data structures.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrEmpty indicates queue is empty.
	ErrEmpty = errors.New("queue is empty")
)

Functions

This section is empty.

Types

type Queue

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

Queue is a simple synchronized queue, just like a channel with infinite buffer size.

func NewQueue

func NewQueue() *Queue

NewQueue creates a new Queue.

func (*Queue) Get

func (q *Queue) Get(ctx context.Context) (interface{}, error)

Get gets an item from queue, block until ctx done.

func (*Queue) GetNoWait

func (q *Queue) GetNoWait() (interface{}, error)

GetNoWait gets an item from queue immediately, ErrEmpty returned if queue is empty.

func (*Queue) Len

func (q *Queue) Len() int

Len returns the number of items.

func (*Queue) Put

func (q *Queue) Put(item interface{})

Put puts an item into queue, always no wait.

type Ring

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

Ring is a FIFO circular slice. It is not goroutine safe.

func NewRing

func NewRing() *Ring

NewRing creates a new Ring.

func (*Ring) Append

func (r *Ring) Append(item interface{})

Append appends an item to "tail" of the ring.

func (*Ring) Len

func (r *Ring) Len() int

Len returns length(not capacity) of the ring.

func (*Ring) Peek

func (r *Ring) Peek() interface{}

Peek peeks the item from "head" of the ring.

func (*Ring) Pop

func (r *Ring) Pop() interface{}

Pop pops the item from "head" of the ring.

Jump to

Keyboard shortcuts

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