pubsub

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: MIT Imports: 5 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package pubsub implements PUBLISH/SUBSCRIBE with exact channels and glob patterns.

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
}

func New

func New() *Hub

func (*Hub) Channels

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

Channels lists active channels matching pattern ("" = all).

func (*Hub) Count

func (h *Hub) Count(s Subscriber) int

Count returns how many channels + patterns s is subscribed to.

func (*Hub) HasSubscribers

func (h *Hub) HasSubscribers() bool

HasSubscribers is a lock-free check used to skip building events nobody listens to.

func (*Hub) NumPat

func (h *Hub) NumPat() int

NumPat returns the number of distinct patterns.

func (*Hub) NumSub

func (h *Hub) NumSub(channel string) int

NumSub returns the subscriber count of a channel.

func (*Hub) PSubscribe

func (h *Hub) PSubscribe(s Subscriber, patterns ...string) []resp.Value

PSubscribe adds patterns and returns the "psubscribe" confirmation replies.

func (*Hub) PUnsubscribe

func (h *Hub) PUnsubscribe(s Subscriber, patterns ...string) []resp.Value

PUnsubscribe removes patterns (all if none given).

func (*Hub) Publish

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

Publish delivers msg and returns the number of receivers.

func (*Hub) RemoveAll

func (h *Hub) RemoveAll(s Subscriber)

RemoveAll drops every subscription of s (on disconnect).

func (*Hub) Subscribe

func (h *Hub) Subscribe(s Subscriber, channels ...string) []resp.Value

Subscribe adds channels and returns the "subscribe" confirmation replies.

func (*Hub) Unsubscribe

func (h *Hub) Unsubscribe(s Subscriber, channels ...string) []resp.Value

Unsubscribe removes channels (all if none given).

type Subscriber

type Subscriber interface {
	Push(v resp.Value) bool
	ClientID() int64
}

Subscriber receives messages. Push must not block.

Jump to

Keyboard shortcuts

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