|
|
|
|
|
by insanitybit
1010 days 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. |
|
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.