Skip to content

Commit

Permalink
optimize pubsub.Publish function
Browse files Browse the repository at this point in the history
Signed-off-by: Shijiang Wei <mountkin@gmail.com>
  • Loading branch information
mountkin committed Feb 15, 2016
1 parent b1594c5 commit 1e0f1ec
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkg/pubsub/publisher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 1e0f1ec

Please sign in to comment.