Skip to content

Commit

Permalink
eventbus: add wildcard subscription type; getter to enumerate known t…
Browse files Browse the repository at this point in the history
…ypes (#153)
  • Loading branch information
raulk committed May 20, 2020
1 parent 55f9d72 commit 994ccbf
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion core/event/bus.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
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
Expand All @@ -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
Expand Down Expand Up @@ -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))
Expand Down Expand Up @@ -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
}

0 comments on commit 994ccbf

Please sign in to comment.