Introduce reset_{at|after} functions for Ticker.

This commit is contained in:
Frostie314159 2023-12-11 13:27:55 +01:00
parent 2d2bd679ee
commit 663fa2addd
No known key found for this signature in database
GPG Key ID: 0C2C22C244C8223F

View File

@ -184,6 +184,16 @@ impl Ticker {
self.expires_at = Instant::now() + self.duration; 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. /// Waits for the next tick.
pub fn next(&mut self) -> impl Future<Output = ()> + '_ { pub fn next(&mut self) -> impl Future<Output = ()> + '_ {
poll_fn(|cx| { poll_fn(|cx| {