Created
February 16, 2021 19:03
-
-
Save pepoviola/be4e892d5bf34cc9865ad6c6dbc86e97 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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