Skip to content

Commit 0a6e078

Browse files
authored
Merge pull request #19 from libp2p/fix/16
fix: serialize publishing
2 parents 0988e77 + 02effd2 commit 0a6e078

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

p2p/host/eventbus/basic.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ func (b *basicBus) Subscribe(evtTypes interface{}, opts ...event.SubscriptionOpt
173173
out.nodes[i] = n
174174
}, func(n *node) {
175175
if n.keepLast {
176-
l := n.last.Load()
176+
l := n.last
177177
if l == nil {
178178
return
179179
}
@@ -223,15 +223,15 @@ func (b *basicBus) Emitter(evtType interface{}, opts ...event.EmitterOpt) (e eve
223223

224224
type node struct {
225225
// Note: make sure to NEVER lock basicBus.lk when this lock is held
226-
lk sync.RWMutex
226+
lk sync.Mutex
227227

228228
typ reflect.Type
229229

230230
// emitter ref count
231231
nEmitters int32
232232

233233
keepLast bool
234-
last atomic.Value
234+
last interface{}
235235

236236
sinks []chan interface{}
237237
}
@@ -248,13 +248,13 @@ func (n *node) emit(event interface{}) {
248248
panic(fmt.Sprintf("Emit called with wrong type. expected: %s, got: %s", n.typ, typ))
249249
}
250250

251-
n.lk.RLock()
251+
n.lk.Lock()
252252
if n.keepLast {
253-
n.last.Store(event)
253+
n.last = event
254254
}
255255

256256
for _, ch := range n.sinks {
257257
ch <- event
258258
}
259-
n.lk.RUnlock()
259+
n.lk.Unlock()
260260
}

0 commit comments

Comments
 (0)