Skip to content

Instantly share code, notes, and snippets.

@BruceChen7
Last active April 14, 2022 07:26
Show Gist options
  • Save BruceChen7/807bcecd4c684543a1cf4a6a917ce821 to your computer and use it in GitHub Desktop.
Save BruceChen7/807bcecd4c684543a1cf4a6a917ce821 to your computer and use it in GitHub Desktop.
#golang#sync#waitgroup
var (
wg sync.WaitGroup
seriesSetChan = make(chan genericSeriesSet)
)
// Schedule all Selects for all queriers we know about.
for _, querier := range q.queriers {
wg.Add(1)
go func(qr genericQuerier) {
defer wg.Done()
// We need to sort for NewMergeSeriesSet to work.
seriesSetChan <- qr.Select(true, hints, matchers...)
}(querier)
}
go func() {
wg.Wait()
close(seriesSetChan)
}()
// 获取series
for r := range seriesSetChan {
seriesSets = append(seriesSets, r)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment