Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add will_fire method that indicates if a timer will fire #106

Merged
merged 1 commit into from
Dec 29, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,29 @@ impl Timer {
}
}

/// Indicates whether or not this timer will ever fire.
///
/// [`never()`] will never fire, and timers created with [`after()`] or [`at()`] will fire
/// if the duration is not too large.
///
/// # Examples
///
/// ```
/// use async_io::Timer;
/// use std::time::Duration;
///
/// // `never` will never fire.
/// assert!(!Timer::never().will_fire());
///
/// // `after` will fire if the duration is not too large.
/// assert!(Timer::after(Duration::from_secs(1)).will_fire());
/// assert!(!Timer::after(Duration::MAX).will_fire());
/// ```
#[inline]
pub fn will_fire(&self) -> bool {
self.when.is_some()
}

/// Sets the timer to emit an en event once after the given duration of time.
///
/// Note that resetting a timer is different from creating a new timer because
Expand Down