Skip to content

Instantly share code, notes, and snippets.

@pepoviola
Created February 16, 2021 19:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pepoviola/be4e892d5bf34cc9865ad6c6dbc86e97 to your computer and use it in GitHub Desktop.
Save pepoviola/be4e892d5bf34cc9865ad6c6dbc86e97 to your computer and use it in GitHub Desktop.
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