hub

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: May 2, 2026 License: MIT Imports: 1 Imported by: 0

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 NewHub

func NewHub[T any]() *Hub[T]

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]) Subscribe

func (h *Hub[T]) Subscribe() chan T

func (*Hub[T]) Unsubscribe

func (h *Hub[T]) Unsubscribe(ch chan T)

Jump to

Keyboard shortcuts

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