Skip to content

Commit

Permalink
time: support IntoFuture with timeout (#6666)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexheretic authored Jul 22, 2024
1 parent feb742c commit 6e845b7
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions tokio/src/time/timeout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
};

use pin_project_lite::pin_project;
use std::future::Future;
use std::future::{Future, IntoFuture};
use std::pin::Pin;
use std::task::{self, Poll};

Expand Down Expand Up @@ -83,9 +83,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<F>(duration: Duration, future: F) -> Timeout<F>
pub fn timeout<F>(duration: Duration, future: F) -> Timeout<F::IntoFuture>
where
F: Future,
F: IntoFuture,
{
let location = trace::caller_location();

Expand All @@ -94,7 +94,7 @@ where
Some(deadline) => Sleep::new_timeout(deadline, location),
None => Sleep::far_future(location),
};
Timeout::new_with_delay(future, delay)
Timeout::new_with_delay(future.into_future(), delay)
}

/// Requires a `Future` to complete before the specified instant in time.
Expand Down Expand Up @@ -142,14 +142,14 @@ where
/// }
/// # }
/// ```
pub fn timeout_at<F>(deadline: Instant, future: F) -> Timeout<F>
pub fn timeout_at<F>(deadline: Instant, future: F) -> Timeout<F::IntoFuture>
where
F: Future,
F: IntoFuture,
{
let delay = sleep_until(deadline);

Timeout {
value: future,
value: future.into_future(),
delay,
}
}
Expand Down

0 comments on commit 6e845b7

Please sign in to comment.