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.
func MaskFromMaskable ¶
MaskFromMaskable extracts mask from an interface.
func (*Mask) FromUint64 ¶
FromUint64 will set a mask to the uint64 value.
func (*Mask) MergeMaskable ¶
MergeMaskable will merge other into t.
func (Mask) SingleType ¶
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 (*PubSub[T, M]) NumSubscribers ¶
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 ¶
Subscribers returns the number of current subscribers for all types.