broadcast

package
v0.31.1 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package broadcast provides a Single-Producer Multi-Consumer (SPMC) ring buffer for broadcasting state snapshots without blocking the producer.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cursor

type Cursor struct {
	Seq uint64
}

Cursor tracks a single consumer's read position.

type Topic

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

Topic is an SPMC ring buffer. Producer writes sequentially; consumers maintain private cursors.

func NewTopic

func NewTopic[T any](capacity int) *Topic[T]

NewTopic creates a topic with a power-of-two capacity.

func (*Topic[T]) Publish

func (t *Topic[T]) Publish(msg T)

Publish stores a message and increments the sequence. Concurrency: strictly single-producer.

func (*Topic[T]) Read

func (t *Topic[T]) Read(c *Cursor, dst []T) int

Read copies available messages into dst. Returns the number of items read. If the consumer falls behind the buffer capacity, it is fast-forwarded to the oldest available surviving message to prevent stale reads or buffer overrun.

Jump to

Keyboard shortcuts

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