Documentation
¶
Overview ¶
Package hub describes event hubs that allow providers to broadcast events and allow consumers to receive them
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EventBatcher ¶
type EventBatcher struct {
// contains filtered or unexported fields
}
func NewEventBatcher ¶
func NewEventBatcher(batchInterval time.Duration) *EventBatcher
func (*EventBatcher) BatchedEvents ¶
func (b *EventBatcher) BatchedEvents() chan struct{}
BatchedEvents allows consumers to receive batched events from a channel
func (*EventBatcher) Notify ¶
func (b *EventBatcher) Notify()
Notify posts an event to the EventBatcher. If the EventBatcher is currently sleeping, then Notify will wake the EventBatcher and the EventBatcher will post a batched event after the batchInterval duration
type NotifyHub ¶
type NotifyHub[T interface{}] struct {
// contains filtered or unexported fields
}
NotifyHub is responsible for broadcasting generic events to subscribers Example usage:
notifyHub := hub.NewNotifyHub[string](20)
go func() {
sub, id := notifyHub.Subscribe()
defer notifyHub.Unsubscribe(id)
for payload := range sub {
fmt.Printf("Received payload %#v\n", payload)
}
}()
time.Sleep(10 * time.Millisecond)
notifyHub.Broadcast("foobar")
time.Sleep(10 * time.Millisecond)
Expected output:
Received payload "foobar"
func NewNotifyHub ¶
NewNotifyHub creates a new hub for broadcasting events to subscribers
func (*NotifyHub[T]) Broadcast ¶
func (h *NotifyHub[T]) Broadcast(payload T)
Broadcast sends the message to all subscribers of this hub
func (*NotifyHub[T]) Unsubscribe ¶
Unsubscribe removes a hub subscriber