Skip to content

docs: Fix various documentation issues for Timer #129

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

Merged
merged 1 commit into from
Apr 10, 2023
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
21 changes: 21 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,16 @@ impl Timer {
/// [`never()`] will never fire, and timers created with [`after()`] or [`at()`] will fire
/// if the duration is not too large.
///
/// [`never()`]: Timer::never()
/// [`after()`]: Timer::after()
/// [`at()`]: Timer::at()
///
/// # Examples
///
/// ```
/// # futures_lite::future::block_on(async {
/// use async_io::Timer;
/// use futures_lite::prelude::*;
/// use std::time::Duration;
///
/// // `never` will never fire.
Expand All @@ -294,6 +300,19 @@ impl Timer {
/// // `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());
///
/// // However, once an `after` timer has fired, it will never fire again.
/// let mut t = Timer::after(Duration::from_secs(1));
/// assert!(t.will_fire());
/// (&mut t).await;
/// assert!(!t.will_fire());
///
/// // Interval timers will fire periodically.
/// let mut t = Timer::interval(Duration::from_secs(1));
/// assert!(t.will_fire());
/// t.next().await;
/// assert!(t.will_fire());
/// # });
/// ```
#[inline]
pub fn will_fire(&self) -> bool {
Expand Down Expand Up @@ -473,6 +492,8 @@ impl Stream for Timer {
// Register the timer in the reactor.
let id = Reactor::get().insert_timer(next, cx.waker());
this.id_and_waker = Some((id, cx.waker().clone()));
} else {
this.when = None;
}
return Poll::Ready(Some(result_time));
} else {
Expand Down