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.
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.
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.
Good point. Yes that would also work
There was a problem hiding this comment.
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> { |
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
futuresmodule, 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
spawnandidlewith the same mindset. I don't particularly like havingspawn,spawn_local,spawn_local_with_priority,spawn_with_priority,spawn_within,spawn_within_with_priority, ...