1use super::File;
2
3use futures::{Future, Poll};
4
5use std::fs::OpenOptions as StdOpenOptions;
6use std::io;
7use std::path::Path;
8
9#[derive(Debug)]
11pub struct OpenFuture<P> {
12 options: StdOpenOptions,
13 path: P,
14}
15
16impl<P> OpenFuture<P>
17where
18 P: AsRef<Path> + Send + 'static,
19{
20 pub(crate) fn new(options: StdOpenOptions, path: P) -> Self {
21 OpenFuture { options, path }
22 }
23}
24
25impl<P> Future for OpenFuture<P>
26where
27 P: AsRef<Path> + Send + 'static,
28{
29 type Item = File;
30 type Error = io::Error;
31
32 fn poll(&mut self) -> Poll<Self::Item, Self::Error> {
33 let std = try_ready!(::blocking_io(|| self.options.open(&self.path)));
34
35 let file = File::from_std(std);
36 Ok(file.into())
37 }
38}