socketry / async-http

MIT License
298 stars 45 forks source link

Add timeout usage example #60

Closed bruno- closed 3 years ago

bruno- commented 3 years ago

Hi,

I first wanted to open an issue with a question: "how to set an internet request timeout?". After investigating for some time, I think I got it right so I'm submitting this PR so other's don't have to spend the time.

Here's a more nuanced question:

Is it better to set a timeout directly on Async::HTTP::Endpoint instance? Or it's just fine to wrap Async::HTTP::Internet requests in a task.with_timeout block? Are there any advantages to using low-level Async::HTTP::Endpoint directly?

ioquatix commented 3 years ago

I like this blog post which explains the difference between the two approaches.

https://vorpus.org/blog/timeouts-and-cancellation-for-humans/

I think this PR is fine.

bruno- commented 3 years ago

Thank you for the blog post link.

I think this PR is fine.

Ok.

bruno- commented 3 years ago

I accidentally hit close PR button, reopening.

ioquatix commented 3 years ago

Thanks for your contribution.