optimize pubsub.Publish function

Signed-off-by: Shijiang Wei <mountkin@gmail.com>
Upstream-commit: 1e0f1ec52543bc83099fb91cd34dca4d38100e6f
Component: engine
This commit is contained in:
Shijiang Wei
2016-02-15 19:25:21 +08:00
parent 6ebcbbfdd8
commit 97fcfe9c7e
+5 -1
View File
@@ -64,10 +64,14 @@ func (p *Publisher) Evict(sub chan interface{}) {
// Publish sends the data in v to all subscribers currently registered with the publisher.
func (p *Publisher) Publish(v interface{}) {
p.m.RLock()
if len(p.subscribers) == 0 {
p.m.RUnlock()
return
}
wg := new(sync.WaitGroup)
for sub, topic := range p.subscribers {
wg.Add(1)
go p.sendTopic(sub, topic, v, wg)
}
wg.Wait()