[SwarmCluster] Add RLock to Cluster.Pull

Use sync.WaitGroup (go-way) to wait for a collection
of pulling goroutines.

Signed-off-by: Anton Tiurin <noxiouz@yandex.ru>
This commit is contained in:
Anton Tiurin 2015-04-08 22:30:23 +03:00
parent b221baf4ed
commit 2b4bbf1ef2
1 changed files with 10 additions and 6 deletions

View File

@ -199,10 +199,15 @@ func (c *Cluster) RemoveImage(image *cluster.Image) ([]*dockerclient.ImageDelete
// Pull is exported
func (c *Cluster) Pull(name string, callback func(what, status string)) {
size := len(c.engines)
done := make(chan bool, size)
var wg sync.WaitGroup
c.RLock()
for _, n := range c.engines {
wg.Add(1)
go func(nn *cluster.Engine) {
defer wg.Done()
if callback != nil {
callback(nn.Name, "")
}
@ -214,12 +219,11 @@ func (c *Cluster) Pull(name string, callback func(what, status string)) {
callback(nn.Name, "downloaded")
}
}
done <- true
}(n)
}
for i := 0; i < size; i++ {
<-done
}
c.RUnlock()
wg.Wait()
}
// Containers returns all the containers in the cluster.