// main
for _, url := range urls {
go getUsersData(url, in)
}
// gorutine
func getUsersData(url string, in chan ResultData) {
res1, err := request1
// ....
res2, err := request2
}
import "time"
rate := time.Second / 10
throttle := time.Tick(rate)
for req := range requests {
<-throttle // rate limit our Service.Method RPCs
go client.Call("Service.Method", req, ...)
}
import "time"
rate := time.Second / 10
burstLimit := 100
tick := time.NewTicker(rate)
defer tick.Stop()
throttle := make(chan time.Time, burstLimit)
go func() {
for t := range tick.C {
select {
case throttle <- t:
default:
}
} // does not exit after tick.Stop()
}()
for req := range requests {
<-throttle // rate limit our Service.Method RPCs
go client.Call("Service.Method", req, ...)
}