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
time: introduce sleep
and sleep_until
functions
#2826
Conversation
tokio/src/time/delay.rs
Outdated
let registration = Registration::new(deadline, Duration::from_millis(0)); | ||
Delay { registration } | ||
} | ||
|
||
/// Waits until `deadline` is reached. Alias for [`sleep_until`](sleep_until). | ||
pub fn delay_until(deadline: Instant) -> Delay { |
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.
The main branch of Tokio is targetting 0.3, not 0.2. This means that this aliasing isn't strictly necessary unless you want to backport this to 0.2 (personally, I think that's a good idea, but I'll let others weigh in). If this is backported this to 0.2, then I'd add a #[deprecated]
attribute to delay_until
with the message "delay_until is deprecated and will be removed in Tokio 0.3; use sleep_until instead."
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.
I like the idea of removing them in v0.3 and having it backported to v0.2 with a #[deprecated]
on the delay
versions.
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.
Yeah, It just wasn't clear to me from the linked issue what should happen to delay_until
and delay_for
. My reasoning is that is doesn't really hurt to keep both versions in 0.3 and beyond but I'm happy either way.
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.
Ok, so we'll go with the deprecation notice. This means I'll need to change every internal use of these two functions right? @davidbarsky @Darksonn . I mean throughout the entire repo.
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.
If we switch to sleep_*
fns, I don't want to maintain an alias.
Regarding backporting to 0.2, I don't have a strong opinion either way. If it were me, I probably wouldn't bother. If others think it is valuable, I will punt to them.
If the goal is to be consistent with the |
@hawkw I vote for keeping it in time. |
@hawkw I also like |
Oh, I misread @hawkw's preference. So we'll keep them in |
So, I went through all usages of the delay functions and I'm actually inclined to leave them and just provide aliases to It's probably not that big of a deal but internally there is this recurring concept of |
I do like the consistency with std from putting it in |
One thing we could do, although this might be even more confusing, is put a |
I think I prefer this option. |
Just pushed a commit deprecating |
Thanks @carllerche. I think this is ready. |
Is this blocked on some decision, or? |
It might be blocked on a decision. I'm in favor of backporting and deprecating the |
I think it makes sense too. |
If the |
This is a PR against master, which is targeting 0.3. The old fns should just be removed. If the intent is to release a deprecation in 0.2, the best strategy would be to open this PR against the 0.2 branch, merge that, then create a merge PR from 0.2 -> master. This will keep everything in sync. I also don't see a clear consensus on the final 0.3 API. Is the plan to rename the fns to |
I don't follow the question. These function would be the public constructors to the future? Are you saying the problem is that the return value is not nameable? |
The issue is more that there would be no immediately obvious way to construct |
@cdmistman this pr just renames It seems we are a bit stuck. I propose the following, if you agree:
|
Removed the |
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.
I think this is good.
This PR replaces
delay_for
withsleep
anddelay_until
withsleep_until
but does not remove the original functions.Documentation is changed to make
sleep
andsleep_until
look like the 'original' functions anddelay_for
anddelay_until
are aliases.Because of the way the functions are wired up internally, I don't think tests need to change but would be happy to rename them or add some if considered necessary.
#2770