| 20 | } |
| 21 | |
| 22 | func (d *imageDownloader) DownloadImages(plugins []metadata.Plugin) { |
| 23 | // ten work slots |
| 24 | sem := make(chan struct{}, 20) |
| 25 | var wg sync.WaitGroup |
| 26 | for i := range plugins { |
| 27 | wg.Add(1) |
| 28 | go func(plugin *metadata.Plugin) { |
| 29 | defer wg.Done() |
| 30 | // wait for a slot |
| 31 | sem <- struct{}{} |
| 32 | defer func() { |
| 33 | // free up a slot |
| 34 | <-sem |
| 35 | }() |
| 36 | if err := d.downloadImage(plugin); err != nil { |
| 37 | log.Println("ERR:", errors.Wrap(err, "DownloadImages")) |
| 38 | } |
| 39 | }(&plugins[i]) |
| 40 | } |
| 41 | wg.Wait() |
| 42 | } |
| 43 | |
| 44 | func (d *imageDownloader) downloadImage(plugin *metadata.Plugin) error { |
| 45 | ext := path.Ext(plugin.ImageURL) |