Placeholder for options in the interface

This commit is contained in:
Łukasz Magiera 2019-06-13 10:04:12 +02:00
parent 20825daa1b
commit 246814bc1e
2 changed files with 13 additions and 4 deletions

View File

@ -67,7 +67,7 @@ func (b *bus) tryDropNode(evtType interface{}) {
b.lk.Unlock()
}
func (b *bus) Subscribe(evtType interface{}) (s <-chan interface{}, c CancelFunc, err error) {
func (b *bus) Subscribe(evtType interface{}, _ ...SubOption) (s <-chan interface{}, c CancelFunc, err error) {
err = b.withNode(evtType, func(n *node) {
out, i := n.sub(0)
s = out
@ -85,7 +85,7 @@ func (b *bus) Subscribe(evtType interface{}) (s <-chan interface{}, c CancelFunc
return
}
func (b *bus) Emitter(evtType interface{}) (e EmitFunc, c CancelFunc, err error) {
func (b *bus) Emitter(evtType interface{}, _ ...EmitterOption) (e EmitFunc, c CancelFunc, err error) {
err = b.withNode(evtType, func(n *node) {
atomic.AddInt32(&n.nEmitters, 1)
closed := false
@ -118,6 +118,9 @@ type node struct {
nEmitters int32
nSinks int
// TODO: we could make emit a bit faster by making this into an array, but
// it doesn't seem needed for now
sinks map[int]chan interface{}
}

View File

@ -1,5 +1,11 @@
package event
type SubSettings struct {}
type SubOption func(*SubSettings)
type EmitterSettings struct {}
type EmitterOption func(*EmitterSettings)
type Bus interface {
// Subscribe creates new subscription. Failing to drain the incoming channel
// will cause publishers to get blocked
@ -12,10 +18,10 @@ type Bus interface {
// defer cancel()
//
// evt := (<-sub).(os.Signal) // guaranteed to be safe
Subscribe(eventType interface{}) (<-chan interface{}, CancelFunc, error)
Subscribe(eventType interface{}, opts ...SubOption) (<-chan interface{}, CancelFunc, error)
Emitter(eventType interface{}) (EmitFunc, CancelFunc, error)
Emitter(eventType interface{}, opts ...EmitterOption) (EmitFunc, CancelFunc, error)
}
// EmitFunc emits events. If any channel subscribed to the topic is blocked,