Simplify throttle loop
This commit is contained in:
@@ -32,14 +32,12 @@ func NewClient(rate uint) *Client {
|
|||||||
// Drill loops over the passed reqs channel and executes each request.
|
// Drill loops over the passed reqs channel and executes each request.
|
||||||
// It is throttled to the qps specified in the initializer
|
// It is throttled to the qps specified in the initializer
|
||||||
func (c *Client) Drill(reqs chan *http.Request, res chan *Response) {
|
func (c *Client) Drill(reqs chan *http.Request, res chan *Response) {
|
||||||
for _ = range time.Tick(time.Duration(1e9 / c.rate)) {
|
throttle := time.Tick(time.Duration(1e9 / c.rate))
|
||||||
if req, ok := <-reqs; !ok {
|
for req := range reqs {
|
||||||
break
|
<-throttle
|
||||||
} else {
|
|
||||||
go c.Do(req, res)
|
go c.Do(req, res)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// Do executes the passed http.Request and puts a generated *Response into res.
|
// Do executes the passed http.Request and puts a generated *Response into res.
|
||||||
func (c *Client) Do(req *http.Request, res chan *Response) {
|
func (c *Client) Do(req *http.Request, res chan *Response) {
|
||||||
|
|||||||
Reference in New Issue
Block a user