Merge pull request #3833 from embediver/main

Add cancel safety notes to Ticker
This commit is contained in:
Dario Nieuwenhuis 2025-02-02 22:53:02 +00:00 committed by GitHub
commit 69925764dc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

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() {