Skip to content

Commit c02ad50

Browse files
authored
Listen for context cancellation during backoff period (#44)
awesome!
1 parent d2ad9ec commit c02ad50

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

pester.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -335,8 +335,13 @@ func (c *Client) pester(p params) (*http.Response, error) {
335335
resp.Body.Close()
336336
}
337337

338+
select {
338339
// prevent a 0 from causing the tick to block, pass additional microsecond
339-
<-time.After(c.Backoff(i) + 1*time.Microsecond)
340+
case <-time.After(c.Backoff(i) + 1*time.Microsecond):
341+
// allow context cancellation to cancel during backoff
342+
case <-req.Context().Done():
343+
return
344+
}
340345
}
341346
}(n, request)
342347

0 commit comments

Comments
 (0)