pubsub

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2024 License: MPL-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrSubscriptionTerminated = errors.New("broker terminated the subscription")

ErrSubscriptionTerminated is for use by subscribers to indicate that their subscription has been terminated by the broker.

Functions

This section is empty.

Types

type Broker

type Broker[T any] struct {
	// contains filtered or unexported fields
}

Broker allows clients to publish events and subscribe to events

func NewBroker

func NewBroker[T any](logger Logger) *Broker[T]

func (*Broker[T]) Publish

func (b *Broker[T]) Publish(t resource.EventType, payload T)

Publish an event to subscribers.

TODO: don't forceably unsubscribe full subscribers: subscribers in pug typically aren't setup to re-subscribe

func (*Broker[T]) Subscribe

func (b *Broker[T]) Subscribe(ctx context.Context) <-chan resource.Event[T]

Subscribe subscribes the caller to a stream of events. The caller can close the subscription by either canceling the context or calling the returned unsubscribe function.

type Logger

type Logger interface {
	Debug(msg string, args ...any)
	Info(msg string, args ...any)
	Warn(msg string, args ...any)
	Error(msg string, args ...any)
}

Jump to

Keyboard shortcuts

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