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

time: document return type of timeout #5118

Merged
merged 1 commit into from Oct 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions tokio/src/time/error.rs
Expand Up @@ -41,6 +41,9 @@ impl From<Kind> for Error {
}

/// Errors returned by `Timeout`.
///
/// This error is returned when a timeout expires before the function was able
/// to finish.
#[derive(Debug, PartialEq)]
pub struct Elapsed(());

Expand Down
20 changes: 16 additions & 4 deletions tokio/src/time/timeout.rs
Expand Up @@ -21,6 +21,12 @@ use std::task::{self, Poll};
/// value is returned. Otherwise, an error is returned and the future is
/// canceled.
///
/// This function returns a future whose return type is [`Result`]`<T,`[`Elapsed`]`>`, where `T` is the
/// return type of the provided future.
///
/// [`Result`]: std::result::Result
/// [`Elapsed`]: crate::time::error::Elapsed
///
/// # Cancellation
///
/// Cancelling a timeout is done by dropping the future. No additional cleanup
Expand Down Expand Up @@ -68,9 +74,9 @@ use std::task::{self, Poll};
/// [`Builder::enable_time`]: crate::runtime::Builder::enable_time
/// [`Builder::enable_all`]: crate::runtime::Builder::enable_all
#[track_caller]
pub fn timeout<T>(duration: Duration, future: T) -> Timeout<T>
pub fn timeout<F>(duration: Duration, future: F) -> Timeout<F>
where
T: Future,
F: Future,
{
let location = trace::caller_location();

Expand All @@ -87,6 +93,12 @@ where
/// If the future completes before the instant is reached, then the completed
/// value is returned. Otherwise, an error is returned.
///
/// This function returns a future whose return type is [`Result`]`<T,`[`Elapsed`]`>`, where `T` is the
/// return type of the provided future.
///
/// [`Result`]: std::result::Result
/// [`Elapsed`]: crate::time::error::Elapsed
///
/// # Cancellation
///
/// Cancelling a timeout is done by dropping the future. No additional cleanup
Expand Down Expand Up @@ -116,9 +128,9 @@ where
/// }
/// # }
/// ```
pub fn timeout_at<T>(deadline: Instant, future: T) -> Timeout<T>
pub fn timeout_at<F>(deadline: Instant, future: F) -> Timeout<F>
where
T: Future,
F: Future,
{
let delay = sleep_until(deadline);

Expand Down