Skip to content

Commit

Permalink
Listen for context cancellation during backoff period (#44)
Browse files Browse the repository at this point in the history
awesome!
  • Loading branch information
lvanoort authored Jan 14, 2022
1 parent d2ad9ec commit c02ad50
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pester.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit c02ad50

Please sign in to comment.