Merge pull request #1839 from Frostie314159/embassy-time-next

embassy-time: Introduce reset function for Ticker.
This commit is contained in:
Ulf Lilleengen 2023-09-12 22:11:21 +00:00 committed by GitHub
commit 4907ccaa4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -133,7 +133,13 @@ impl Ticker {
Self { expires_at, duration } Self { expires_at, duration }
} }
/// Waits for the next tick /// Resets the ticker back to its original state.
/// This causes the ticker to go back to zero, even if the current tick isn't over yet.
pub fn reset(&mut self) {
self.expires_at = Instant::now() + self.duration;
}
/// 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| {
if self.expires_at <= Instant::now() { if self.expires_at <= Instant::now() {