diff options
Diffstat (limited to 'embassy-time/src/timer.rs')
| -rw-r--r-- | embassy-time/src/timer.rs | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/embassy-time/src/timer.rs b/embassy-time/src/timer.rs index daa4c1699..757c3ff00 100644 --- a/embassy-time/src/timer.rs +++ b/embassy-time/src/timer.rs | |||
| @@ -190,8 +190,20 @@ impl Ticker { | |||
| 190 | self.expires_at = Instant::now() + self.duration; | 190 | self.expires_at = Instant::now() + self.duration; |
| 191 | } | 191 | } |
| 192 | 192 | ||
| 193 | /// Reset the ticker at the deadline. | ||
| 194 | /// If the deadline is in the past, the ticker will fire instantly. | ||
| 195 | pub fn reset_at(&mut self, deadline: Instant) { | ||
| 196 | self.expires_at = deadline + self.duration; | ||
| 197 | } | ||
| 198 | |||
| 199 | /// Resets the ticker, after the specified duration has passed. | ||
| 200 | /// If the specified duration is zero, the next tick will be after the duration of the ticker. | ||
| 201 | pub fn reset_after(&mut self, after: Duration) { | ||
| 202 | self.expires_at = Instant::now() + after + self.duration; | ||
| 203 | } | ||
| 204 | |||
| 193 | /// Waits for the next tick. | 205 | /// Waits for the next tick. |
| 194 | pub fn next(&mut self) -> impl Future<Output = ()> + '_ { | 206 | pub fn next(&mut self) -> impl Future<Output = ()> + Send + Sync + '_ { |
| 195 | poll_fn(|cx| { | 207 | poll_fn(|cx| { |
| 196 | if self.expires_at <= Instant::now() { | 208 | if self.expires_at <= Instant::now() { |
| 197 | let dur = self.duration; | 209 | let dur = self.duration; |
