From ec5f283d150032f721a211b219b584166434790c Mon Sep 17 00:00:00 2001 From: Marvin Gudel Date: Sun, 2 Feb 2025 14:28:45 +0100 Subject: [PATCH] Add cancel safety notes to Ticker --- embassy-time/src/timer.rs | 7 +++++++ 1 file changed, 7 insertions(+) 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 { /// } /// } /// ``` +/// +/// ## Cancel safety +/// It is safe to cancel waiting for the next tick, +/// meaning no tick is lost if the Future is dropped. pub struct Ticker { expires_at: Instant, duration: Duration, @@ -231,6 +235,9 @@ impl Ticker { } /// Waits for the next tick. + /// + /// ## Cancel safety + /// The produced Future is cancel safe, meaning no tick is lost if the Future is dropped. pub fn next(&mut self) -> impl Future + Send + Sync + '_ { poll_fn(|cx| { if self.expires_at <= Instant::now() {