Skip to content

Instantly share code, notes, and snippets.

@jmw511
Created January 6, 2015 20:40
Show Gist options
  • Save jmw511/d0feb500ce0a57b8d17c to your computer and use it in GitHub Desktop.
Save jmw511/d0feb500ce0a57b8d17c to your computer and use it in GitHub Desktop.
PostGraphRequests function
func (api GraphV2) PostGraphRequests(urls []string) ([]BatchResponse, error) {
batchCh := make(chan []BatchResponse)
errs := make(chan error)
responses := []BatchResponse{}
var wg sync.WaitGroup
for _, url := range urls {
wg.Add(1)
go func(url string) {
defer wg.Done()
resps, err := PostBatchFacebookGraphRequest(url)
if err != nil {
errs <- err
return
}
batchCh <- resps
}(url)
}
go func() {
wg.Wait()
close(batchCh)
}()
for resps := range batchCh {
responses = append(responses, resps...)
}
select {
case err := <-errs:
return nil, err
default:
return responses, nil
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment