queue

package
v0.0.0-...-ddf849a Latest Latest
Warning

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

Go to latest
Published: May 15, 2023 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Overview

Package queue implements a non-blocking message queue.

Index

Constants

View Source
const Unbounded int = -1

Unbounded indicates the Queue does not have a limit.

Variables

This section is empty.

Functions

This section is empty.

Types

type Queue

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

Queue implements a multi-producer, single consumer event queue.

func New

func New(limit int) *Queue

New creates a new Queue.

func (*Queue) Close

func (q *Queue) Close() error

Close the queue, preventing any more messages from being sent. Dequeue will return io.EOF.

func (*Queue) Dequeue

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

Dequeue blocks until ctx is canceled or an item can be dequeued. Dequeue will panic if there are multiple concurrent callers.

func (*Queue) Enqueue

func (q *Queue) Enqueue(v interface{})

Enqueue queues an item. Messages are guaranteed to be dequeued in call order. If the queue has reached its limit, the oldest message will be discarded.

func (*Queue) Size

func (q *Queue) Size() int

Size of the elements in the queue.

func (*Queue) TryDequeue

func (q *Queue) TryDequeue() (interface{}, bool)

TryDequeue will return an element from q if one exists.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳