broadcast

package
v0.17.1 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 3 Imported by: 1 module, 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 implements a fan-out event stream with overwrite-on-full semantics. Callers publish with Publisher.Send, and each Subscription receives every message in order until it falls a full ring behind; it then receives a ring.LaggedError saying where to resume instead of stale data. The ring is bounded, so producers never wait on consumers. See ring.RingBuffer for the sequence and slot protocol.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Broadcast

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

Broadcast is a fan-out event stream over a ring.RingBuffer. It mints Publisher and Subscribable handles; it has no lifecycle of its own, subscriptions end via Subscription.Unsubscribe.

func New

func New[T any](capacity uint64) *Broadcast[T]

New constructs a Broadcast with a ring of at least the given capacity, rounded up to a power of two.

func (*Broadcast[T]) NewPublisher

func (b *Broadcast[T]) NewPublisher() Publisher[T]

NewPublisher returns a Publisher, the Send handle for this Broadcast.

func (*Broadcast[T]) NewSubscribable

func (b *Broadcast[T]) NewSubscribable() Subscribable[T]

NewSubscribable returns a Subscribable, the read-only handle for creating subscriptions.

type Publisher

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

Publisher is a Send handle for a Broadcast. It is a value type and safe to copy.

func (Publisher[T]) Send

func (p Publisher[T]) Send(msg T)

Send publishes msg to the ring; it never blocks on readers beyond the per-slot lock.

T is passed by value: callers use pointer or interface element types (e.g. *core.Block), so this is a single-word copy and avoids a pointer-to-pointer.

type Subscribable

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

Subscribable is a read-only handle over a Broadcast's ring. It is a value type and safe to copy.

func (Subscribable[T]) Subscribe

func (s Subscribable[T]) Subscribe() *Subscription[ring.EventOrLag[T]]

Subscribe starts a subscription delivering raw ring.EventOrLag values.

func (Subscribable[T]) SubscribeWith

func (s Subscribable[T]) SubscribeWith[O any](
	transform func(iter.Seq[ring.EventOrLag[T]]) iter.Seq[O],
) *Subscription[O]

SubscribeWith starts a subscription delivering O values: transform maps the ring's ring.EventOrLag iterator to any output iterator, for instance a lag policy yielding T or a mapper yielding a derived type.

type Subscription

type Subscription[O any] struct {
	// contains filtered or unexported fields
}

Subscription is a single consumer delivering O values on Subscription.Recv until Subscription.Unsubscribe.

func (*Subscription[O]) Recv

func (sub *Subscription[O]) Recv() <-chan O

Recv returns the channel delivering this subscription's values; it is closed after Subscription.Unsubscribe.

func (*Subscription[O]) Unsubscribe

func (sub *Subscription[O]) Unsubscribe()

Unsubscribe stops delivery. Cancelling the context fires the iterator's AfterFunc, which wakes a blocked reader so the goroutine exits (see ring.RingBuffer.wakeWaiters). Idempotent.

Directories

Path Synopsis
Package ring implements the MPMC overwrite-on-full ring buffer that backs the broadcast package; see RingBuffer for the sequence and slot protocol.
Package ring implements the MPMC overwrite-on-full ring buffer that backs the broadcast package; see RingBuffer for the sequence and slot protocol.

Jump to

Keyboard shortcuts

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