mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Merge pull request #20408 from cpuguy83/use_pool_for_pubsub_wg
Use pool for pubsub `Publish`'s waitgroups
This commit is contained in:
commit
9a81f206b3
1 changed files with 4 additions and 1 deletions
|
@ -5,6 +5,8 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
var wgPool = sync.Pool{New: func() interface{} { return new(sync.WaitGroup) }}
|
||||
|
||||
// NewPublisher creates a new pub/sub publisher to broadcast messages.
|
||||
// The duration is used as the send timeout as to not block the publisher publishing
|
||||
// messages to other clients if one client is slow or unresponsive.
|
||||
|
@ -69,12 +71,13 @@ func (p *Publisher) Publish(v interface{}) {
|
|||
return
|
||||
}
|
||||
|
||||
wg := new(sync.WaitGroup)
|
||||
wg := wgPool.Get().(*sync.WaitGroup)
|
||||
for sub, topic := range p.subscribers {
|
||||
wg.Add(1)
|
||||
go p.sendTopic(sub, topic, v, wg)
|
||||
}
|
||||
wg.Wait()
|
||||
wgPool.Put(wg)
|
||||
p.m.RUnlock()
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue