mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-29 00:00:11 +02:00
time: add #[track_caller] to FutureExt::timeout (#7588)
Signed-off-by: Martin Tzvetanov Grigorov <[email protected]>
This commit is contained in:
@@ -26,6 +26,7 @@ pub trait FutureExt: Future {
|
|||||||
/// assert!(res.is_err());
|
/// assert!(res.is_err());
|
||||||
/// # }
|
/// # }
|
||||||
/// ```
|
/// ```
|
||||||
|
#[track_caller]
|
||||||
fn timeout(self, timeout: std::time::Duration) -> tokio::time::Timeout<Self>
|
fn timeout(self, timeout: std::time::Duration) -> tokio::time::Timeout<Self>
|
||||||
where
|
where
|
||||||
Self: Sized,
|
Self: Sized,
|
||||||
|
|||||||
@@ -217,6 +217,23 @@ fn delay_queue_reserve_panic_caller() -> Result<(), Box<dyn Error>> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn future_ext_to_panic_caller() -> Result<(), Box<dyn Error>> {
|
||||||
|
use tokio::{sync::oneshot, time::Duration};
|
||||||
|
use tokio_util::future::FutureExt;
|
||||||
|
|
||||||
|
let panic_location_file = test_panic(|| {
|
||||||
|
let (_tx, rx) = oneshot::channel::<()>();
|
||||||
|
// this panics because there is no runtime available
|
||||||
|
let _res = rx.timeout(Duration::from_millis(10));
|
||||||
|
});
|
||||||
|
|
||||||
|
// The panic location should be in this file
|
||||||
|
assert_eq!(&panic_location_file.unwrap(), file!());
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
fn basic() -> Runtime {
|
fn basic() -> Runtime {
|
||||||
tokio::runtime::Builder::new_current_thread()
|
tokio::runtime::Builder::new_current_thread()
|
||||||
.enable_all()
|
.enable_all()
|
||||||
|
|||||||
Reference in New Issue
Block a user