From f71ffc5936f6cec74c03144b899fd7e40aca4008 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1s=20Senart?= Date: Fri, 16 Aug 2013 20:01:05 +0200 Subject: [PATCH] Simplify throttle loop --- client.go | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/client.go b/client.go index 942e0aa..46f5533 100644 --- a/client.go +++ b/client.go @@ -32,12 +32,10 @@ func NewClient(rate uint) *Client { // Drill loops over the passed reqs channel and executes each request. // It is throttled to the qps specified in the initializer func (c *Client) Drill(reqs chan *http.Request, res chan *Response) { - for _ = range time.Tick(time.Duration(1e9 / c.rate)) { - if req, ok := <-reqs; !ok { - break - } else { - go c.Do(req, res) - } + throttle := time.Tick(time.Duration(1e9 / c.rate)) + for req := range reqs { + <-throttle + go c.Do(req, res) } }