Merge pull request #2295 from Frostie314159/reset-at-after
Introduce `reset_{at|after}` functions for ticker.
This commit is contained in:
commit
81cf9d1143
1 changed files with 12 additions and 0 deletions
|
@ -190,6 +190,18 @@ impl Ticker {
|
|||
self.expires_at = Instant::now() + self.duration;
|
||||
}
|
||||
|
||||
/// Reset the ticker at the deadline.
|
||||
/// If the deadline is in the past, the ticker will fire instantly.
|
||||
pub fn reset_at(&mut self, deadline: Instant) {
|
||||
self.expires_at = deadline + self.duration;
|
||||
}
|
||||
|
||||
/// Resets the ticker, after the specified duration has passed.
|
||||
/// If the specified duration is zero, the next tick will be after the duration of the ticker.
|
||||
pub fn reset_after(&mut self, after: Duration) {
|
||||
self.expires_at = Instant::now() + after + self.duration;
|
||||
}
|
||||
|
||||
/// Waits for the next tick.
|
||||
pub fn next(&mut self) -> impl Future<Output = ()> + '_ {
|
||||
poll_fn(|cx| {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue