broadcast

package
v0.37.1 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2026 License: Apache-2.0 Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package broadcast provides a concurrent-producer, multi-consumer ring buffer for broadcasting state snapshots.

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 a multi-consumer ring buffer with serialized concurrent publishers. Consumers maintain private cursors.

func NewTopic

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

NewTopic creates a topic with a power-of-two capacity. It returns nil when the requested capacity exceeds the supported maximum; use NewTopicChecked when the caller needs the error.

func NewTopicChecked added in v0.37.0

func NewTopicChecked[T any](requested int) (*Topic[T], error)

NewTopicChecked creates a topic and reports unsupported capacities.

func (*Topic[T]) Publish

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

Publish stores a message and increments the sequence. Concurrent publishers are serialized; consumers may read concurrently with publishers.

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