diff options
| author | Ulf Lilleengen <[email protected]> | 2023-09-12 22:11:21 +0000 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-09-12 22:11:21 +0000 |
| commit | 4907ccaa4daecb1b25d636795860eee58891548c (patch) | |
| tree | 9413d39845e3c107cc9a2e467176aab11cb7eef1 /embassy-time/src | |
| parent | 2c38dd17b9a5a507fc77d90d78486e4764234752 (diff) | |
| parent | 527bdc57b9c4d5a77f725111570c5add9e646a6b (diff) | |
Merge pull request #1839 from Frostie314159/embassy-time-next
embassy-time: Introduce reset function for Ticker.
Diffstat (limited to 'embassy-time/src')
| -rw-r--r-- | embassy-time/src/timer.rs | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/embassy-time/src/timer.rs b/embassy-time/src/timer.rs index ad5026e62..07ddf473f 100644 --- a/embassy-time/src/timer.rs +++ b/embassy-time/src/timer.rs | |||
| @@ -133,7 +133,13 @@ impl Ticker { | |||
| 133 | Self { expires_at, duration } | 133 | Self { expires_at, duration } |
| 134 | } | 134 | } |
| 135 | 135 | ||
| 136 | /// Waits for the next tick | 136 | /// Resets the ticker back to its original state. |
| 137 | /// This causes the ticker to go back to zero, even if the current tick isn't over yet. | ||
| 138 | pub fn reset(&mut self) { | ||
| 139 | self.expires_at = Instant::now() + self.duration; | ||
| 140 | } | ||
| 141 | |||
| 142 | /// Waits for the next tick. | ||
| 137 | pub fn next(&mut self) -> impl Future<Output = ()> + '_ { | 143 | pub fn next(&mut self) -> impl Future<Output = ()> + '_ { |
| 138 | poll_fn(|cx| { | 144 | poll_fn(|cx| { |
| 139 | if self.expires_at <= Instant::now() { | 145 | if self.expires_at <= Instant::now() { |
