Unverified Commit 26478862 authored by Raúl Kripalani's avatar Raúl Kripalani Committed by GitHub

eventbus: add wildcard subscription type; getter to enumerate known types (#153)

parent 30bf48c8
package event
import "io"
import (
"io"
"reflect"
)
// SubscriptionOpt represents a subscriber option. Use the options exposed by the implementation of choice.
type SubscriptionOpt = func(interface{}) error
......@@ -11,6 +14,14 @@ type EmitterOpt = func(interface{}) error
// CancelFunc closes a subscriber.
type CancelFunc = func()
// wildcardSubscriptionType is a virtual type to represent wildcard
// subscriptions.
type wildcardSubscriptionType interface{}
// WildcardSubscription is the type to subscribe to to receive all events
// emitted in the eventbus.
var WildcardSubscription = new(wildcardSubscriptionType)
// Emitter represents an actor that emits events onto the eventbus.
type Emitter interface {
io.Closer
......@@ -39,6 +50,11 @@ type Bus interface {
//
// Failing to drain the channel may cause publishers to block.
//
// If you want to subscribe to ALL events emitted in the bus, use
// `WildcardSubscription` as the `eventType`:
//
// eventbus.Subscribe(WildcardSubscription)
//
// Simple example
//
// sub, err := eventbus.Subscribe(new(EventType))
......@@ -71,4 +87,11 @@ type Bus interface {
// defer em.Close() // MUST call this after being done with the emitter
// em.Emit(EventT{})
Emitter(eventType interface{}, opts ...EmitterOpt) (Emitter, error)
// GetAllEventTypes returns all the event types that this bus knows about
// (having emitters and subscribers). It omits the WildcardSubscription.
//
// The caller is guaranteed that this function will only return value types;
// no pointer types will be returned.
GetAllEventTypes() []reflect.Type
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment