Add cancel safety notes to Ticker

This commit is contained in:
Marvin Gudel 2025-02-02 14:28:45 +01:00
parent ae5ad91bbb
commit ec5f283d15

View File

@ -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<Output = ()> + Send + Sync + '_ {
poll_fn(|cx| {
if self.expires_at <= Instant::now() {