-
Notifications
You must be signed in to change notification settings - Fork 144
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
Make gloo::timer
's future-based design like stdlib
#162
Labels
enhancement
New feature or request
Comments
gloo::timer
's future-based design like stdlib
Sorry for filing an incomplete issue. I have updated the issue title and description. |
I like this approach. How about we add a function for fn sleep(duration: Duration) -> TimeoutFuture {
// ...
}
// somewhere else
sleep(Duration::from_secs(5)).await
// after 5 seconds |
Merged
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Summary
Make
gloo::timer
's future-based API likestd
/tokio
.Motivation
Why are we doing this? What problems does it solve?
This issue purposes to make gloo::timer's design more like Rust's standard library.
There was a similar discussion for the tokio library years ago about making the Tokio's sleep / timeout design to be similar to the standard library's design.
tokio-rs/tokio#2770
tokio-rs/tokio#2826
The rationale:
std::thread::sleep
takes aDuration
which is a better design than taking a number in millisecond in my opinion.gloo::timer::sleep(Duration::from_secs(1)).await
is easier to understand and remember thangloo::timer::TimeoutFuture::new(1000).await
for most people.Detailed Explanation
Drawbacks, Rationale, and Alternatives
Does this design have drawbacks?
It breaks compatibility.
Are there alternative approaches?
The current approach of
gloo::timer
.Why is this design the best of all designs available?
This is a design that meets the expectation for people coming from both Rust and other common programming languages.
What prior art exists?
This is the design used by
std
andtokio
.The text was updated successfully, but these errors were encountered: