Introduce reset_{at|after} functions for Ticker.
This commit is contained in:
parent
2d2bd679ee
commit
663fa2addd
1 changed files with 10 additions and 0 deletions
|
@ -184,6 +184,16 @@ impl Ticker {
|
|||
self.expires_at = Instant::now() + self.duration;
|
||||
}
|
||||
|
||||
/// Reset the ticker to fire for the next time on the deadline.
|
||||
pub fn reset_at(&mut self, deadline: Instant) {
|
||||
self.expires_at = deadline;
|
||||
}
|
||||
|
||||
/// Resets the ticker, after the specified duration has passed.
|
||||
pub fn reset_after(&mut self, after: Duration) {
|
||||
self.expires_at = Instant::now() + after;
|
||||
}
|
||||
|
||||
/// 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