Created
May 10, 2020 12:48
-
-
Save Mathspy/6c718974ac7b8cc835bd46215b36dc15 to your computer and use it in GitHub Desktop.
Detect if a reader is ready to be read from
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
async fn is_reader_ready<R>(reader: &mut R) -> bool where R: AsyncRead + Unpin { | |
let mut me = &mut *reader; | |
poll_fn(|cx| { | |
let mut v = []; | |
Poll::Ready(Pin::new(&mut me).poll_read(cx, &mut v[..]).is_ready()) | |
}).await | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Don't actually use this. I originally wrote it for testing purposes before realising