Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Distributor ¶
type Distributor[E any, K comparable] struct { // contains filtered or unexported fields }
Distributor supports subscribing to get a Reader
func New ¶
func New[E any, K comparable](key func(E) K) *Distributor[E, K]
func (*Distributor[E, K]) Submit ¶
func (k *Distributor[E, K]) Submit(e E) <-chan struct{}
Submit pushes an event into the Distributor. The returned channel is closed when the event has been fully consumed. If there are no subscribers, the event will be considered consumed immediately.
Submit is thread-safe
func (*Distributor[E, K]) Subscribe ¶
func (k *Distributor[E, K]) Subscribe(value K) *Reader[E]
Subscribe creates a Reader that listens for events where the key matches a specific value. It is recommended that immediately after a Subscribe, that you defer the Unsubscribe:
reader := distributor.Subscribe(someValue) defer reader.Unsubscribe()
Subscribe is thread-safe
type Reader ¶
type Reader[E any] struct { eventdistributor.Reader[E] // contains filtered or unexported fields }
Reader is used by a single subscriber to get events. Select on reader.WaitChan() to know when there is an event ready to consume and then use reader.Consume() to get the event. Use reader.Unsubscribe() when the reader is no longer needed. Reader embeds eventdistributor's Reader.
func (*Reader[E]) Unsubscribe ¶
func (r *Reader[E]) Unsubscribe()
Unsubscribe releases a Reader. After an Unsubscribe, the WaitChan() and Consume() methods should not be used. It is important to Unsubscribe() because otherwise the Distributor will keep buffering events that are meant for the reader.