Documentation ¶
Index ¶
- Variables
- type Mask
- type Maskable
- type PubSub
- func (ps *PubSub[T, M]) NumSubscribers(mask M) int32
- func (ps *PubSub[T, M]) Publish(item T)
- func (ps *PubSub[T, M]) Subscribe(mask M, subCh chan T, doneCh <-chan struct{}, filter func(entry T) bool) error
- func (ps *PubSub[T, M]) SubscribeJSON(mask M, subCh chan<- []byte, doneCh <-chan struct{}, filter func(entry T) bool, ...) error
- func (ps *PubSub[T, M]) Subscribers() int32
- type Sub
Constants ¶
This section is empty.
Variables ¶
var GetByteBuffer = func() []byte { return make([]byte, 0, 4096) }
GetByteBuffer returns a byte buffer from the pool.
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 non-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]) SubscribeJSON ¶
func (ps *PubSub[T, M]) SubscribeJSON(mask M, subCh chan<- []byte, doneCh <-chan struct{}, filter func(entry T) bool, wg *sync.WaitGroup) error
SubscribeJSON - Adds a subscriber to pubsub system and returns results with JSON encoding.
func (*PubSub[T, M]) Subscribers ¶
Subscribers returns the number of current subscribers for all types.