1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

optimize pubsub.Publish function

Signed-off-by: Shijiang Wei <mountkin@gmail.com>
This commit is contained in:
Shijiang Wei 2016-01-29 13:08:20 +08:00
parent b1594c59f5
commit 1e0f1ec525

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. // Publish sends the data in v to all subscribers currently registered with the publisher.
func (p *Publisher) Publish(v interface{}) { func (p *Publisher) Publish(v interface{}) {
p.m.RLock() p.m.RLock()
if len(p.subscribers) == 0 {
p.m.RUnlock()
return
}
wg := new(sync.WaitGroup) wg := new(sync.WaitGroup)
for sub, topic := range p.subscribers { for sub, topic := range p.subscribers {
wg.Add(1) wg.Add(1)
go p.sendTopic(sub, topic, v, wg) go p.sendTopic(sub, topic, v, wg)
} }
wg.Wait() wg.Wait()