gofri / go-github-ratelimit

A GoLang HTTP RoundTripper that handles GitHub API secondary rate limits
MIT License
41 stars 13 forks source link

Make sleep interruptible when request context expire. #28

Open cedric-appdirect opened 1 month ago

cedric-appdirect commented 1 month ago

When using this library in a CLI tool, I like to connect a context to CTRL-C signal allowing for early interruption. The problem is that with very long second rate limit, you can get the CLI lock in a sleep that can not be interrupted which is not ideal. This PR address that problem by using the context from the request and a timer channel to handle this scenario.

This comes with test for verifying that SleepWithContext behave as expected. I have introduced the use of testify by habit mostly, but the test look nicer with it in my opinion. Let me know if you prefer a different approach for the test.