pubsub

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 3, 2024 License: Apache-2.0 Imports: 3 Imported by: 8

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