Fix race condition in pubsub package.

Closes #97
This commit is contained in:
Victor Vrantchan
2017-03-21 00:41:36 -04:00
committed by Victor Vrantchan
parent 6065d1f2c9
commit e000fec3c0

View File

@@ -22,9 +22,11 @@ func (p *Inmem) dispatch() {
for {
select {
case ev := <-p.publish:
p.mtx.Lock()
for _, sub := range p.subscriptions[ev.Topic] {
go func(s subscription) { s.eventChan <- ev }(sub)
}
p.mtx.Unlock()
}
}
}