sequencer

package
v0.24.1 Latest Latest
Warning

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

Go to latest
Published: May 23, 2026 License: MPL-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Channel

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

Channel[T] is a multi-producer, single-consumer channel of items with monotonicaly-increasing sequence numbers. Items can be sent in any order, but they are always received in order of their sequence number. It is unsafe to call Next concurrently with itself, or to call Add/Reserve concurrently with another Add/Reserve call for the same sequence number. Otherwise, methods are safe to call concurrently.

func New

func New[T any](initialSequenceNumber uint64, capacity uint64) *Channel[T]

func (*Channel[T]) Add

func (seq *Channel[T]) Add(ctx context.Context, sequenceNumber uint64, item *T) error

Send an item with the given sequence number. Blocks if the channel does not have capacity for the item. It is undefined behavior to send a sequence number that has previously been sent.

func (*Channel[T]) Cap

func (seq *Channel[T]) Cap() uint64

func (*Channel[T]) Next

func (seq *Channel[T]) Next(ctx context.Context) (*T, error)

Return the item with the next sequence number, blocking if necessary. Not safe to call concurrently with other Next calls.

func (*Channel[T]) Reserve added in v0.20.0

func (seq *Channel[T]) Reserve(ctx context.Context, sequenceNumber uint64) error

Wait until the channel has capacity for an item with the given sequence number. After this function returns nil, calling Add with the same sequence number will not block.

Jump to

Keyboard shortcuts

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