pubsub

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: May 1, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrCancelled = errors.New("cancelled")

ErrCancelled error returned when context is cancelled

View Source
var ErrTimeout = errors.New("timeout")

ErrTimeout error returned when timeout occurs

Functions

This section is empty.

Types

type Payload

type Payload[T comparable, P any] struct {
	Topic T
	Msg   P
}

type PubSub

type PubSub[T comparable, P any] struct {
	sync.Mutex
	// contains filtered or unexported fields
}

PubSub contains and manage the map of topics -> subscribers

func NewPubSub

func NewPubSub[T comparable, P any]() *PubSub[T, P]

func (*PubSub[T, P]) Pub

func (p *PubSub[T, P]) Pub(topic T, msg P)

Pub shortcut for publish which ignore the error

func (*PubSub[T, P]) Subscribe

func (p *PubSub[T, P]) Subscribe(topics []T) *Sub[T, P]

Subscribe is an alias for NewSub

type Sub

type Sub[T comparable, P any] struct {
	// contains filtered or unexported fields
}

Sub subscriber will receive messages published on a Topic in his ch

func (*Sub[T, P]) Close

func (s *Sub[T, P]) Close()

Close will remove the subscriber from the Topic subscribers

func (*Sub[T, P]) Receive

func (s *Sub[T, P]) Receive() (topic T, msg P, err error)

Receive returns a message

func (*Sub[T, P]) ReceiveCh

func (s *Sub[T, P]) ReceiveCh() <-chan Payload[T, P]

ReceiveCh returns a message

func (*Sub[T, P]) ReceiveTimeout

func (s *Sub[T, P]) ReceiveTimeout(timeout time.Duration) (topic T, msg P, err error)

ReceiveTimeout returns a message received on the channel or timeout

func (*Sub[T, P]) ReceiveTimeout2

func (s *Sub[T, P]) ReceiveTimeout2(timeout time.Duration, c1 <-chan struct{}) (topic T, msg P, err error)

ReceiveTimeout2 returns a message received on the channel or timeout

Jump to

Keyboard shortcuts

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