aboutsummaryrefslogtreecommitdiff
path: root/src/time/timeout.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/time/timeout.rs')
-rw-r--r--src/time/timeout.rs16
1 files changed, 11 insertions, 5 deletions
diff --git a/src/time/timeout.rs b/src/time/timeout.rs
index 61964ad..6725caa 100644
--- a/src/time/timeout.rs
+++ b/src/time/timeout.rs
@@ -4,14 +4,17 @@
//!
//! [`Timeout`]: struct@Timeout
-use crate::time::{error::Elapsed, sleep_until, Duration, Instant, Sleep};
+use crate::{
+ time::{error::Elapsed, sleep_until, Duration, Instant, Sleep},
+ util::trace,
+};
use pin_project_lite::pin_project;
use std::future::Future;
use std::pin::Pin;
use std::task::{self, Poll};
-/// Require a `Future` to complete before the specified duration has elapsed.
+/// Requires a `Future` to complete before the specified duration has elapsed.
///
/// If the future completes before the duration has elapsed, then the completed
/// value is returned. Otherwise, an error is returned and the future is
@@ -45,19 +48,22 @@ use std::task::{self, Poll};
/// }
/// # }
/// ```
+#[cfg_attr(tokio_track_caller, track_caller)]
pub fn timeout<T>(duration: Duration, future: T) -> Timeout<T>
where
T: Future,
{
+ let location = trace::caller_location();
+
let deadline = Instant::now().checked_add(duration);
let delay = match deadline {
- Some(deadline) => Sleep::new_timeout(deadline),
- None => Sleep::far_future(),
+ Some(deadline) => Sleep::new_timeout(deadline, location),
+ None => Sleep::far_future(location),
};
Timeout::new_with_delay(future, delay)
}
-/// Require a `Future` to complete before the specified instant in time.
+/// Requires a `Future` to complete before the specified instant in time.
///
/// If the future completes before the instant is reached, then the completed
/// value is returned. Otherwise, an error is returned.