It's more like "I want to be able to put timeouts in my code". 99% of why I want async is so that if something takes too long I can just stop that. That is incredibly hard to do without async.
It's more like "I want to be able to put timeouts in my code". 99% of why I want async is so that if something takes too long I can just stop that. That is incredibly hard to do without async.
This is extremely difficult. I mentioned elsewhere that the only way to kill a thread is through the pthread_cancel API, which is very dangerous.
Languages with larger runtimes can get around this because they have all sorts of things like global locks or implicit cooperative yielding. So they don't ever have to "kill" a thread, they actually just join it when it yields.
What if my work isn't related to socket timeouts? For example, downloading a multi-part file? I may want a very long socket timeout but still have a distinct timeout for the individual chunked operations. It might take 30 seconds to grab an entire file but if one chunk takes >3 seconds I may want to time out.
What if my work involves no IO at all?
The ability to cancel work in progress is extremely important to me.
Yeah that’s an issue. In Go they sync it (thread safe), which in Rust would translate to interior mutability.
> What if I want to do per-request timeouts?
Ah you’re right in http2 there can be multiple concurrent reqs per conn. Go still allows request based timeouts, but I wonder if that’s possible with the limited primitives in std. It’s also true that this is a case where the inner conn should not be exposed.
> I may want a very long socket timeout but still have a distinct timeout for the individual chunked operations.
Right! That’s typically done by extending the deadline for every chunk. Ie the user/caller needs a way to set timeouts.
> The ability to cancel work in progress is extremely important to me.
Yes for sure. I was just curious. Btw which libs are you referring to for network requests? I’d like to see their APIs.
Consider this: https://docs.rs/rusoto_s3/latest/rusoto_s3/trait.S3.html
You're given a trait and, understandably, this trait does not expose any sockets to you (it may not even be backed by sockets).