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