spsc

package
v3.0.0-alpha.11 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2022 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package spsc implements a single-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 single-producer, single-consumer queue. Create one with New(), and send with Tx.Send(). Tx and Rx are each not safe for use by multiple goroutines, but two separate goroutines can use Tx and Rx respectively.

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
JackTT - Gopher 🇻🇳