Skip to content

Commit f9ba3f7

Browse files
authored
Add will_fire method (#106)
1 parent 2353752 commit f9ba3f7

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/lib.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,29 @@ impl Timer {
277277
}
278278
}
279279

280+
/// Indicates whether or not this timer will ever fire.
281+
///
282+
/// [`never()`] will never fire, and timers created with [`after()`] or [`at()`] will fire
283+
/// if the duration is not too large.
284+
///
285+
/// # Examples
286+
///
287+
/// ```
288+
/// use async_io::Timer;
289+
/// use std::time::Duration;
290+
///
291+
/// // `never` will never fire.
292+
/// assert!(!Timer::never().will_fire());
293+
///
294+
/// // `after` will fire if the duration is not too large.
295+
/// assert!(Timer::after(Duration::from_secs(1)).will_fire());
296+
/// assert!(!Timer::after(Duration::MAX).will_fire());
297+
/// ```
298+
#[inline]
299+
pub fn will_fire(&self) -> bool {
300+
self.when.is_some()
301+
}
302+
280303
/// Sets the timer to emit an en event once after the given duration of time.
281304
///
282305
/// Note that resetting a timer is different from creating a new timer because

0 commit comments

Comments
 (0)