pubsub

package
v0.0.0-...-fb0f190 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2022 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 struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

PubSub holds publishers and subscribers

func New

func New(maxSubscribers int32) *PubSub

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

func (*PubSub) NumSubscribers

func (ps *PubSub) NumSubscribers(m Maskable) int32

NumSubscribers returns the number of current subscribers, If t is non-nil, the type is checked against the active subscribed types, and 0 will be returned if nobody is subscribed for the type, otherwise the *total* number of subscribers is returned.

func (*PubSub) Publish

func (ps *PubSub) Publish(item Maskable)

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) Subscribe

func (ps *PubSub) Subscribe(mask Mask, subCh chan Maskable, doneCh <-chan struct{}, filter func(entry Maskable) bool) error

Subscribe - Adds a subscriber to pubsub system

type Sub

type Sub 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