Help us shape the future of Go! Take the 2026 Go Developer Survey

pubsub

package
v2.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package pubsub implements channel and pattern based publish/subscribe.

Publishing never blocks on subscribers: each Subscriber decides how to deliver (typically by queueing to a per-connection writer) and slow subscribers are dropped by their transport rather than stalling publishers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Hub

type Hub struct {
	// contains filtered or unexported fields
}

Hub routes messages from publishers to subscribers.

func NewHub

func NewHub() *Hub

NewHub returns an empty hub.

func (*Hub) Channels

func (h *Hub) Channels(pattern string) []string

Channels returns active channels matching pattern ("" means all), sorted.

func (*Hub) NumPat

func (h *Hub) NumPat() int

NumPat returns the number of distinct pattern subscriptions.

func (*Hub) NumSub

func (h *Hub) NumSub(channels ...string) []int

NumSub returns the subscriber count of each channel.

func (*Hub) PSubscribe

func (h *Hub) PSubscribe(s Subscriber, pattern string) bool

PSubscribe adds s to a glob pattern.

func (*Hub) PUnsubscribe

func (h *Hub) PUnsubscribe(s Subscriber, pattern string) bool

PUnsubscribe removes s from a pattern.

func (*Hub) Publish

func (h *Hub) Publish(channel, message string) int

Publish delivers message to subscribers of channel and of matching patterns, returning the number of deliveries.

func (*Hub) Subscribe

func (h *Hub) Subscribe(s Subscriber, channel string) bool

Subscribe adds s to channel. It reports whether s was newly subscribed.

func (*Hub) Unsubscribe

func (h *Hub) Unsubscribe(s Subscriber, channel string) bool

Unsubscribe removes s from channel.

func (*Hub) UnsubscribeAll

func (h *Hub) UnsubscribeAll(s Subscriber, channels, patterns []string)

UnsubscribeAll removes every subscription of s, e.g. when its connection closes.

type Subscriber

type Subscriber interface {
	Deliver(channel, pattern, message string)
}

Subscriber receives published messages. Deliver must not block. pattern is empty for messages received through a channel subscription.

Jump to

Keyboard shortcuts

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