pubsub

package
v0.0.0-...-aeecd87 Latest Latest
Warning

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

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

Documentation

Overview

Package pubsub provides a simple publish/subscribe mechanism for a generic type using a radix tree of topics.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DuplicateSubscription

type DuplicateSubscription struct{}

DuplicateSubscription is an error returned when a channel is already subscribed.

func (DuplicateSubscription) Error

func (DuplicateSubscription) Error() string

Error implements the error interface.

type Interface

type Interface[T any] interface {
	// Process starts the pubsub instance.  It will block until the exit channel is closed.
	Process(exit <-chan struct{})

	// Publish sends a value to all subscribers for any published value starting with the given topic.  Any
	// subscribers that are not ready to receive the value will be skipped.
	Publish(v T, topic ...string)

	// Subscribe adds a subscriber channel for any published value starting with the given topic.  Returns
	// DuplicateSubscription if the channel is already subscribed to the topic.
	Subscribe(ch chan<- T, topic ...string) error

	// Unsubscribe removes a subscriber channel for any published value starting with the given topic.  This
	// should match the original channel passed to Subscribe.  Does nothing if there is no subscriber.
	// The channel will be closed when it is unsubscribed.
	Unsubscribe(ch chan<- T, topic ...string)
}

Interface is a simple publish/subscribe mechanism for a generic type using a radix tree of topics.

func New

func New[T any]() Interface[T]

New creates a new pubsub instance for a generic type.

Jump to

Keyboard shortcuts

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