mirror of
https://github.com/embassy-rs/embassy.git
synced 2024-11-22 06:42:32 +00:00
Merge pull request #2295 from Frostie314159/reset-at-after
Introduce `reset_{at|after}` functions for ticker.
This commit is contained in:
commit
81cf9d1143
@ -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…
Reference in New Issue
Block a user