mpsc

package
v3.0.0-alpha.15 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2022 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package mpsc implements a multiple-producer, single-consumer queue.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Queue

type Queue[T any] struct {
	Tx[T]
	Rx[T]
}

A multiple-producer, single-consumer queue. Create one with New(), and send from many gorotuines with Tx.Send(). Only one gorotuine may call Rx.Recv().

func New

func New[T any]() *Queue[T]

Create a new, initially empty Queue.

type Rx

type Rx[T any] struct {
	// contains filtered or unexported fields
}

The receive end of a Queue.

func (*Rx[T]) Recv

func (rx *Rx[T]) Recv(ctx context.Context) (T, error)

Receive a message from the queue. Blocks if the queue is empty. If the context ends before the receive happens, this returns ctx.Err().

func (*Rx[T]) TryRecv

func (rx *Rx[T]) TryRecv() (v T, ok bool)

Try to receive a message from the queue. If successful, ok will be true. If the queue is empty, this will return immediately with ok = false.

type Tx

type Tx[T any] struct {
	// contains filtered or unexported fields
}

The send/transmit end of a Queue.

func (*Tx[T]) Send

func (tx *Tx[T]) Send(v T)

Send a message on the queue.

Jump to

Keyboard shortcuts

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