-
-
Notifications
You must be signed in to change notification settings - Fork 114
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
Draft: Futures module #1033
base: main
Are you sure you want to change the base?
Draft: Futures module #1033
Conversation
That sounds like a nice idea. You probably won't get around distinguishing |
self.priority = priority; | ||
self | ||
} | ||
pub fn precision(mut self, precision: SchedulingPrecision) -> Self { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe the precision should be defined based on whether the Duration
has fractional seconds or not? Or is that too implicit?
Otherwise maybe having a sleep(Duration)
and sleep_seconds(u32)
would be simpler API.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can't make it implicit based on the choosen Duration
, because the user could want to actually wait 2000
milliseconds precisely, and not 2
seconds roughly.
What about having the methods precision_seconds
, precision_milliseconds
, so that we can remove the public enum SchedulingPrecision
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. Yes that would also work
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thinking about it... In gtk adding a new enum for a specific function seems to be pretty normal. I think it fits adding an enum here as well
} | ||
} | ||
|
||
pub struct Timeout<F: Future> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This all needs docs
e8c34fd
to
5b2608a
Compare
Related issue: #935
I think there are currently too many timeout functions, with too many combinations of scheduling priority and scheduling precision (second, millisecond).
Instead of just moving every timeout function to a
futures
module, I've decided to redesign the API taking advantage of the Builder pattern and the IntoFuture trait.API example:
I'm still looking if it's possible to redesign
spawn
andidle
with the same mindset. I don't particularly like havingspawn
,spawn_local
,spawn_local_with_priority
,spawn_with_priority
,spawn_within
,spawn_within_with_priority
, ...