pubsub

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2025 License: Apache-2.0 Imports: 3 Imported by: 2 modules, 9 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.

README

Non-blocking pubsub in Go

Install

go get github.com/troian/pubsub

View the API Documentation.

Documentation

Overview

Package pubsub implements a simple multi-topic pub-sub library.

Topics must be strings and messages of any type can be published. A topic can have any number of subscribers and all of them receive messages published on the topic.

Index

Constants

This section is empty.

Variables

View Source
var ErrorCongestionMsgLost = errors.New("PubSub Congestion: message lost, try again")

Functions

This section is empty.

Types

type PubOption

type PubOption func(*pubOptions)

func WithRetain

func WithRetain() PubOption

type PubSub

type PubSub interface {
	Publisher
	Subscriber
	Shutdown()
}

func New

func New(ctx context.Context, capacity int) PubSub

New creates a new PubSub and starts a goroutine for handling operations. The capacity of the channels created by Sub and SubOnce will be as specified. The default is the blocking variant, since this is the original behaviour

type Publisher

type Publisher interface {
	Pub(msg interface{}, topics []string, opts ...PubOption)
	TryPub(msg interface{}, topics []string, opts ...PubOption) bool
}

type Subscriber

type Subscriber interface {
	Sub(topics ...string) <-chan interface{}
	SubOnce(topics ...string) <-chan interface{}
	AddTopics(ch <-chan interface{}, topics ...string)
	Unsub(ch <-chan interface{}, topics ...string)
}

Jump to

Keyboard shortcuts

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