Skip to content

Instantly share code, notes, and snippets.

@rainerborene
Created October 6, 2014 20:15
Show Gist options
  • Save rainerborene/57d262bf6ea8f57f1ec3 to your computer and use it in GitHub Desktop.
Save rainerborene/57d262bf6ea8f57f1ec3 to your computer and use it in GitHub Desktop.
func BatchGeocode(ips []string) []*GeoIP {
ch := make(chan *GeoIP, len(ips))
responses := []*GeoIP{}
for _, ip := range ips {
go func(ip string) {
geo, err := Geocode(ip)
if err != nil {
log.Fatal(err)
}
ch <- geo
}(ip)
}
for {
select {
case r := <-ch:
responses = append(responses, r)
if len(responses) == len(ips) {
return responses
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment