mirror of
https://github.com/libp2p/go-eventbus.git
synced 2026-08-21 15:13:27 +08:00
Address @bigs review
This commit is contained in:
11
basic.go
11
basic.go
@@ -40,8 +40,8 @@ func (b *bus) withNode(evtType interface{}, cb func(*node)) error {
|
||||
|
||||
n.lk.Lock()
|
||||
b.lk.Unlock()
|
||||
defer n.lk.Unlock()
|
||||
cb(n)
|
||||
n.lk.Unlock()
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -116,8 +116,11 @@ type node struct {
|
||||
|
||||
typ reflect.Type
|
||||
|
||||
// emitter ref count
|
||||
nEmitters int32
|
||||
nSinks int
|
||||
|
||||
// sink index counter
|
||||
sinkC int
|
||||
|
||||
// TODO: we could make emit a bit faster by making this into an array, but
|
||||
// it doesn't seem needed for now
|
||||
@@ -134,8 +137,8 @@ func newNode(typ reflect.Type) *node {
|
||||
|
||||
func (n *node) sub(buf int) (chan interface{}, int) {
|
||||
out := make(chan interface{}, buf)
|
||||
i := n.nSinks
|
||||
n.nSinks++
|
||||
i := n.sinkC
|
||||
n.sinkC++
|
||||
n.sinks[i] = out
|
||||
return out, i
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user