From c02ad50519b40e0097bff5cf70a8d732765440ae Mon Sep 17 00:00:00 2001 From: Luke Van Oort Date: Fri, 14 Jan 2022 10:31:19 -0500 Subject: [PATCH] Listen for context cancellation during backoff period (#44) awesome! --- pester.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pester.go b/pester.go index 8021e60..ce326ed 100644 --- a/pester.go +++ b/pester.go @@ -335,8 +335,13 @@ func (c *Client) pester(p params) (*http.Response, error) { resp.Body.Close() } + select { // prevent a 0 from causing the tick to block, pass additional microsecond - <-time.After(c.Backoff(i) + 1*time.Microsecond) + case <-time.After(c.Backoff(i) + 1*time.Microsecond): + // allow context cancellation to cancel during backoff + case <-req.Context().Done(): + return + } } }(n, request)