Skip to content

Commit 6e845b7

Browse files
authored
time: support IntoFuture with timeout (#6666)
1 parent feb742c commit 6e845b7

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

tokio/src/time/timeout.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use crate::{
1111
};
1212

1313
use pin_project_lite::pin_project;
14-
use std::future::Future;
14+
use std::future::{Future, IntoFuture};
1515
use std::pin::Pin;
1616
use std::task::{self, Poll};
1717

@@ -83,9 +83,9 @@ use std::task::{self, Poll};
8383
/// [`Builder::enable_time`]: crate::runtime::Builder::enable_time
8484
/// [`Builder::enable_all`]: crate::runtime::Builder::enable_all
8585
#[track_caller]
86-
pub fn timeout<F>(duration: Duration, future: F) -> Timeout<F>
86+
pub fn timeout<F>(duration: Duration, future: F) -> Timeout<F::IntoFuture>
8787
where
88-
F: Future,
88+
F: IntoFuture,
8989
{
9090
let location = trace::caller_location();
9191

@@ -94,7 +94,7 @@ where
9494
Some(deadline) => Sleep::new_timeout(deadline, location),
9595
None => Sleep::far_future(location),
9696
};
97-
Timeout::new_with_delay(future, delay)
97+
Timeout::new_with_delay(future.into_future(), delay)
9898
}
9999

100100
/// Requires a `Future` to complete before the specified instant in time.
@@ -142,14 +142,14 @@ where
142142
/// }
143143
/// # }
144144
/// ```
145-
pub fn timeout_at<F>(deadline: Instant, future: F) -> Timeout<F>
145+
pub fn timeout_at<F>(deadline: Instant, future: F) -> Timeout<F::IntoFuture>
146146
where
147-
F: Future,
147+
F: IntoFuture,
148148
{
149149
let delay = sleep_until(deadline);
150150

151151
Timeout {
152-
value: future,
152+
value: future.into_future(),
153153
delay,
154154
}
155155
}

0 commit comments

Comments
 (0)