From 246814bc1e13cd33263db42e57d6c497f8d8cd25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Magiera?= Date: Thu, 13 Jun 2019 10:04:12 +0200 Subject: [PATCH] Placeholder for options in the interface --- basic.go | 7 +++++-- interface.go | 10 ++++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/basic.go b/basic.go index 10372b8..9554e73 100644 --- a/basic.go +++ b/basic.go @@ -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{} } diff --git a/interface.go b/interface.go index 81150e4..80e9585 100644 --- a/interface.go +++ b/interface.go @@ -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,