Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
p2p
go-p2p-core
Commits
26478862
Unverified
Commit
26478862
authored
May 20, 2020
by
Raúl Kripalani
Committed by
GitHub
May 20, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
eventbus: add wildcard subscription type; getter to enumerate known types (#153)
parent
30bf48c8
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
1 deletion
+24
-1
event/bus.go
event/bus.go
+24
-1
No files found.
event/bus.go
View file @
26478862
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
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment