concurrentGrab fetches multiple profiles concurrently
(sources []profileSource, fetch plugin.Fetcher, obj plugin.ObjTool, ui plugin.UI, tr http.RoundTripper)
| 205 | |
| 206 | // concurrentGrab fetches multiple profiles concurrently |
| 207 | func concurrentGrab(sources []profileSource, fetch plugin.Fetcher, obj plugin.ObjTool, ui plugin.UI, tr http.RoundTripper) (*profile.Profile, plugin.MappingSources, bool, int, error) { |
| 208 | wg := sync.WaitGroup{} |
| 209 | wg.Add(len(sources)) |
| 210 | for i := range sources { |
| 211 | go func(s *profileSource) { |
| 212 | defer wg.Done() |
| 213 | s.p, s.msrc, s.remote, s.err = grabProfile(s.source, s.addr, fetch, obj, ui, tr) |
| 214 | }(&sources[i]) |
| 215 | } |
| 216 | wg.Wait() |
| 217 | |
| 218 | var save bool |
| 219 | profiles := make([]*profile.Profile, 0, len(sources)) |
| 220 | msrcs := make([]plugin.MappingSources, 0, len(sources)) |
| 221 | for i := range sources { |
| 222 | s := &sources[i] |
| 223 | if err := s.err; err != nil { |
| 224 | ui.PrintErr(s.addr + ": " + err.Error()) |
| 225 | continue |
| 226 | } |
| 227 | save = save || s.remote |
| 228 | profiles = append(profiles, s.p) |
| 229 | msrcs = append(msrcs, s.msrc) |
| 230 | *s = profileSource{} |
| 231 | } |
| 232 | |
| 233 | if len(profiles) == 0 { |
| 234 | return nil, nil, false, 0, nil |
| 235 | } |
| 236 | |
| 237 | p, msrc, err := combineProfiles(profiles, msrcs) |
| 238 | if err != nil { |
| 239 | return nil, nil, false, 0, err |
| 240 | } |
| 241 | return p, msrc, save, len(profiles), nil |
| 242 | } |
| 243 | |
| 244 | func combineProfiles(profiles []*profile.Profile, msrcs []plugin.MappingSources) (*profile.Profile, plugin.MappingSources, error) { |
| 245 | // Merge profiles. |
no test coverage detected
searching dependent graphs…