pubsub

package
v0.0.0-...-a6a3a47 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2023 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Mask

type Mask uint64

Mask allows filtering by a bitset mask.

const (
	// MaskAll is the mask for all entries.
	MaskAll Mask = math.MaxUint64
)

func MaskFromMaskable

func MaskFromMaskable(m Maskable) Mask

MaskFromMaskable extracts mask from an interface.

func (Mask) Contains

func (t Mask) Contains(other Mask) bool

Contains returns whether *all* flags in other is present in t.

func (*Mask) FromUint64

func (t *Mask) FromUint64(m uint64)

FromUint64 will set a mask to the uint64 value.

func (Mask) Mask

func (t Mask) Mask() uint64

Mask returns the mask as a uint64.

func (*Mask) Merge

func (t *Mask) Merge(other Mask)

Merge will merge other into t.

func (*Mask) MergeMaskable

func (t *Mask) MergeMaskable(other Maskable)

MergeMaskable will merge other into t.

func (Mask) Overlaps

func (t Mask) Overlaps(other Mask) bool

Overlaps returns whether *any* flags in t overlaps with other.

func (*Mask) SetIf

func (t *Mask) SetIf(b bool, other Mask)

SetIf will add other if b is true.

func (Mask) SingleType

func (t Mask) SingleType() bool

SingleType returns whether t has a single type set.

type Maskable

type Maskable interface {
	Mask() uint64
}

Maskable implementations must return their mask as a 64 bit uint.

type PubSub

type PubSub[T Maskable, M Maskable] struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

PubSub holds publishers and subscribers

func New

func New[T Maskable, M Maskable](maxSubscribers int32) *PubSub[T, M]

New inits a PubSub system with a limit of maximum subscribers unless zero is specified

func (*PubSub[T, M]) NumSubscribers

func (ps *PubSub[T, M]) NumSubscribers(mask M) int32

NumSubscribers returns the number of current subscribers, The mask is checked against the active subscribed types, and 0 will be returned if nobody is subscribed for the type(s).

func (*PubSub[T, M]) Publish

func (ps *PubSub[T, M]) Publish(item T)

Publish message to the subscribers. Note that publish is always nob-blocking send so that we don't block on slow receivers. Hence receivers should use buffered channel so as not to miss the published events.

func (*PubSub[T, M]) Subscribe

func (ps *PubSub[T, M]) Subscribe(mask M, subCh chan T, doneCh <-chan struct{}, filter func(entry T) bool) error

Subscribe - Adds a subscriber to pubsub system

func (*PubSub[T, M]) Subscribers

func (ps *PubSub[T, M]) Subscribers() int32

Subscribers returns the number of current subscribers for all types.

type Sub

type Sub[T Maskable] struct {
	// contains filtered or unexported fields
}

Sub - subscriber entity.

Jump to

Keyboard shortcuts

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