-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Future::timeout() method #6047
Comments
We don't currently have any extension traits for futures in Tokio, and I'm somewhat reluctant to add one. |
@Darksonn can you expand on your reluctance at all? I agree that the postfix interface is more ergonomic, especially when there are several chained method calls before the timeout(
Duration::from_secs(1),
RequestBuilder::new(/*...*/)
.prepare(/*...*/)
.check(/*...*/)
.build(/*...*/)
.send(/*...*/),
)
.await
.wrap_err(/* ... */)?; vs RequestBuilder::new(/*...*/)
.prepare(/*...*/)
.check(/*...*/)
.build(/*...*/)
.send(/*...*/)
.timeout(Duration::from_secs(1))
.await
.wrap_err(/* ... */)?; |
Also curious about why |
We removed |
Feel free to assign this to me, I'll add said extension trait to tokio-util |
Is your feature request related to a problem? Please describe.
Currently, the code to timeout a Future is
I propose it should be possible to write
This results in cleaner code following the fluent style of writing.
Describe the solution you'd like
I propose adding a
Future
extension methodDescribe alternatives you've considered
The current method
timeout(Duration, Future)
works, but is less readable.Additional context
The proposed method used to be in Tokio in the past:
tokio/tokio/src/future.rs
Lines 61 to 66 in 27e5b41
It got removed in #1774 refactoring.
Similar method is implemented in async_std since 2019 async-rs/async-std#600.
The text was updated successfully, but these errors were encountered: