-
-
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
implement extra reset variants for Interval #5878
Conversation
be472be
to
77b08c7
Compare
tokio/src/time/interval.rs
Outdated
|
||
/// Resets the interval to a [`crate::time::Instant`] deadline. | ||
/// | ||
/// This method ignores [`MissedTickBehavior`] strategy. |
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.
It might be better to rephrase this as:
Sets the next tick to expire at the given instant. If the instant is in the past, then the
MissedTickBehavior
strategy will be used to catch up. If the instant is in the future, then the next tick will complete at the given instant, even if that means that it will sleep for longer than the duration of thisInterval
. If theInterval
had any missed ticks before calling this method, then those are discarded.
be4406b
to
2172e0f
Compare
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 is looking good. I see you've still marked it as a draft, though.
/// catch up. If the instant is in the future, then the next tick will | ||
/// complete at the given instant, even if that means that it will sleep for | ||
/// longer than the duration of this [`Interval`]. If the [`Interval`] had |
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.
It seems like the "even if that means that it will sleep for longer than the duration" part is not currently tested.
2172e0f
to
153cc74
Compare
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.
Thanks.
Fixes: #5874
Motivation
The use case is explained in #5874
Solution
It just calls the internal reset on the specified
Instant
.I have added a new field to theInterval
struct to store the previous period.On each tick if previous period isSome()
it will be restored.Integration tests will be added on a later commit.