-
-
Save niksaak/e29590df2a23b3736ce996199c63ff82 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
pub struct LoadFile<'a> { | |
path: Option<&'a str>, | |
data: Mutex<Option<mq::fs::Response>>, | |
} | |
impl LoadFile { | |
pub fn new(path: &str) -> LoadFile { | |
LoadFile { | |
path: Some(path), | |
data: Mutex::new(None), | |
} | |
} | |
} | |
impl Future for LoadFile { | |
fn poll(self: Pin<&mut Self>, ctx: &mut task::Context) -> Poll<Self::Output> { | |
if let Some(path) = path.take() { | |
let waker = ctx.waker().clone(); | |
mq::fs::load_file(path, move |response| { | |
*self.data.lock() = Some(response); | |
waker.wake(); | |
}); | |
match self.data.lock() { | |
None => Poll::Pending, | |
Some(response) => Poll::Ready(response), | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment