Skip to content

Instantly share code, notes, and snippets.

@keegancsmith
Created July 25, 2015 23:43
Show Gist options
  • Save keegancsmith/4d6bec9f64ba2f665f4f to your computer and use it in GitHub Desktop.
Save keegancsmith/4d6bec9f64ba2f665f4f to your computer and use it in GitHub Desktop.
diff --git a/store/unit_store.go b/store/unit_store.go
index 515ed9c..e145bd0 100644
--- a/store/unit_store.go
+++ b/store/unit_store.go
@@ -90,10 +90,8 @@ func (s unitStores) Refs(f ...RefFilter) ([]*graph.Ref, error) {
}
c_unitStores_Refs_last_numUnitsQueried = 0
- var (
- allRefs []*graph.Ref
- allRefsMu sync.Mutex
- )
+
+ allRefsChan := make(chan *graph.Ref)
par := parallel.NewRun(storeFetchPar)
for u, us := range uss {
if us == nil {
@@ -139,16 +137,24 @@ func (s unitStores) Refs(f ...RefFilter) ([]*graph.Ref, error) {
if ref.DefUnit == "" {
ref.DefUnit = u.Name
}
+ allRefsChan <- ref
}
- allRefsMu.Lock()
- allRefs = append(allRefs, refs...)
- allRefsMu.Unlock()
return nil
})
}
- err = par.Wait()
- return allRefs, err
+ var parErr error
+ go func() {
+ parErr = par.Wait()
+ close(allRefsChan)
+ }()
+
+ var allRefs []*graph.Ref
+ for ref := range allRefsChan {
+ allRefs = append(allRefs, ref)
+ }
+
+ return allRefs, parErr
}
func cleanForImport(data *graph.Output, repo, unitType, unit string) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment