Every HTTP request library needs to support connection timeout, response timeout, etc. to prevent app from hanging in poor network conditions. Merely an "abandoned" request could still sit wait forever, wasting memory.

Except in async , which has an interesting model: when you stop polling a Future and drop it, it explicitly aborts everything it has been doing. So if the app gives up on the request, it will get cleaned up automatically even if it was stuck. No need for special timeout API.

· · Web · 1 · 6 · 8

@kornel If I want to write a program to retry requesting when timeout happens, will it be easy in Rust async?

@veer66 @kornel You basically end up creating a Future from the Http Request, and a timeout timer. Which ever one resolves first is what you go with. If it's the timeout, retry the request, if it's the request then handle it.

@veer66 Yes. You can make a for loop for the retries! Tokio also has an easy wrapper for adding timeout to any future.

Sign in to participate in the conversation

Server run by the main developers of the project 🐘 It is not focused on any particular niche interest - everyone is welcome as long as you follow our code of conduct!