mirror of
https://github.com/libp2p/go-eventbus.git
synced 2025-02-07 05:50:08 +08:00
Placeholder for options in the interface
This commit is contained in:
parent
20825daa1b
commit
246814bc1e
7
basic.go
7
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{}
|
||||
}
|
||||
|
||||
|
10
interface.go
10
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,
|
||||
|
Loading…
Reference in New Issue
Block a user