Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
use std::future::Future;
use std::pin::Pin;
use std::task::{Context, Poll};
use std::time::{Duration, Instant};
struct Inspect<F>(F);
impl<F: Future> Future for Inspect<F> {
type Output = F::Output;
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let t = Instant::now();
let res = unsafe { self.map_unchecked_mut(|f| &mut f.0) }.poll(cx);
let t = t.elapsed();
if t > Duration::from_millis(10) {
warn!("future polled for {:?}", t);
}
res
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.