4 ms·
Relying on the socket APIs is a bit painful. For one thing, what if that socket is shared across tasks? What if I want to do per-request timeouts? What if I don
by insanitybit 3y ago
Relying on the socket APIs is a bit painful. For one thing, what if that socket is shared across tasks? What if I want to do per-request timeouts? What if I don't want to expose the socket APIs to callers?
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.
- klabb3 3y ago> For one thing, what if that socket is shared across tasks? 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.
- insanitybit 3y ago> Btw which libs are you referring to for network requests? Consider this: https://docs.rs/rusoto_s3/latest/rusoto_s3/trait.S3.html 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).