Created
July 17, 2020 04:18
-
-
Save wilbeibi/5326824b249bc091c8daebb9f7129648 to your computer and use it in GitHub Desktop.
This file contains 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