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 ¶
New constructs a Broadcast with a ring of at least the given capacity, rounded up to a power of two.
func (*Broadcast[T]) NewPublisher ¶
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.
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. |