diff options
| author | Frostie314159 <[email protected]> | 2023-12-11 13:27:55 +0100 |
|---|---|---|
| committer | Frostie314159 <[email protected]> | 2023-12-11 13:27:55 +0100 |
| commit | 663fa2addd30463328f6186e14f98680b4a35c9b (patch) | |
| tree | cc1ebc5d6926f8a4b0cb6cb8789f4d369e108819 /embassy-time/src | |
| parent | 2d2bd679ee2d3247c94dd66fa8ec40ffa07090ab (diff) | |
Introduce reset_{at|after} functions for Ticker.
Diffstat (limited to 'embassy-time/src')
| -rw-r--r-- | embassy-time/src/timer.rs | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/embassy-time/src/timer.rs b/embassy-time/src/timer.rs index 574d715da..3444d3e24 100644 --- a/embassy-time/src/timer.rs +++ b/embassy-time/src/timer.rs | |||
| @@ -184,6 +184,16 @@ impl Ticker { | |||
| 184 | self.expires_at = Instant::now() + self.duration; | 184 | self.expires_at = Instant::now() + self.duration; |
| 185 | } | 185 | } |
| 186 | 186 | ||
| 187 | /// Reset the ticker to fire for the next time on the deadline. | ||
| 188 | pub fn reset_at(&mut self, deadline: Instant) { | ||
| 189 | self.expires_at = deadline; | ||
| 190 | } | ||
| 191 | |||
| 192 | /// Resets the ticker, after the specified duration has passed. | ||
| 193 | pub fn reset_after(&mut self, after: Duration) { | ||
| 194 | self.expires_at = Instant::now() + after; | ||
| 195 | } | ||
| 196 | |||
| 187 | /// Waits for the next tick. | 197 | /// Waits for the next tick. |
| 188 | pub fn next(&mut self) -> impl Future<Output = ()> + '_ { | 198 | pub fn next(&mut self) -> impl Future<Output = ()> + '_ { |
| 189 | poll_fn(|cx| { | 199 | poll_fn(|cx| { |
