pub trait TimedFutureExt: Future {
// Provided method
fn timed<F>(self, f: F) -> Timed<Self, F> ⓘ
where Self: Sized,
F: FnOnce(Timing) { ... }
}Expand description
An extension trait for Futures that adds the timed method.
Provided Methods§
Sourcefn timed<F>(self, f: F) -> Timed<Self, F> ⓘ
fn timed<F>(self, f: F) -> Timed<Self, F> ⓘ
Instrument a future to record its timing
The busy and idle time for the future will be passed as an argument to the provided
closure. See the documentation for Timing for more details.
§Examples
use future_timed::{TimedFutureExt, Timing};
let output = async {
// Block the executor
std::thread::sleep(Duration::from_micros(200));
tokio::time::sleep(Duration::from_micros(10)).await;
42
}.timed(|Timing { idle, busy }| {
assert!(idle > Duration::from_micros(10));
assert!(busy > Duration::from_micros(200));
})
. await;
assert_eq!(output, 42);