Documentation
¶
Overview ¶
Package hub provides a generic in-memory pub/sub fan-out for typed events. Subscribers receive events on a buffered channel. A subscriber whose buffer is full will drop events rather than block the publisher.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Hub ¶
type Hub[T any] struct { // contains filtered or unexported fields }
func (*Hub[T]) Publish ¶
func (h *Hub[T]) Publish(event T)
Publish delivers event to every current subscriber. A subscriber with a full buffer has the event dropped rather than blocking Publish.
The mutex is held across the fan-out so concurrent Unsubscribe calls cannot close a channel mid-send (which would panic). Since each send is non-blocking (select with default), the hold time remains bounded by the current subscriber count, not by any subscriber's receive speed.
func (*Hub[T]) Unsubscribe ¶
func (h *Hub[T]) Unsubscribe(ch chan T)
Click to show internal directories.
Click to hide internal directories.