Created
October 6, 2014 20:15
-
-
Save rainerborene/57d262bf6ea8f57f1ec3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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