aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarvin Gudel <[email protected]>2025-02-02 14:28:45 +0100
committerMarvin Gudel <[email protected]>2025-02-02 14:28:45 +0100
commitec5f283d150032f721a211b219b584166434790c (patch)
treee6d67779039e14c1df184d65748b28acc278c8b0
parentae5ad91bbb6a158971c858f69ad25ca86025f2be (diff)
Add cancel safety notes to Ticker
-rw-r--r--embassy-time/src/timer.rs7
1 files changed, 7 insertions, 0 deletions
diff --git a/embassy-time/src/timer.rs b/embassy-time/src/timer.rs
index 295ddbd9b..34e5762d2 100644
--- a/embassy-time/src/timer.rs
+++ b/embassy-time/src/timer.rs
@@ -200,6 +200,10 @@ impl Future for Timer {
200/// } 200/// }
201/// } 201/// }
202/// ``` 202/// ```
203///
204/// ## Cancel safety
205/// It is safe to cancel waiting for the next tick,
206/// meaning no tick is lost if the Future is dropped.
203pub struct Ticker { 207pub struct Ticker {
204 expires_at: Instant, 208 expires_at: Instant,
205 duration: Duration, 209 duration: Duration,
@@ -231,6 +235,9 @@ impl Ticker {
231 } 235 }
232 236
233 /// Waits for the next tick. 237 /// Waits for the next tick.
238 ///
239 /// ## Cancel safety
240 /// The produced Future is cancel safe, meaning no tick is lost if the Future is dropped.
234 pub fn next(&mut self) -> impl Future<Output = ()> + Send + Sync + '_ { 241 pub fn next(&mut self) -> impl Future<Output = ()> + Send + Sync + '_ {
235 poll_fn(|cx| { 242 poll_fn(|cx| {
236 if self.expires_at <= Instant::now() { 243 if self.expires_at <= Instant::now() {