1 use std::io;
2 
3 use futures::{Async, Future, Poll};
4 
5 use AsyncWrite;
6 
7 /// A future used to fully flush an I/O object.
8 ///
9 /// Resolves to the underlying I/O object once the flush operation is complete.
10 ///
11 /// Created by the [`flush`] function.
12 ///
13 /// [`flush`]: fn.flush.html
14 #[derive(Debug)]
15 pub struct Flush<A> {
16     a: Option<A>,
17 }
18 
19 /// Creates a future which will entirely flush an I/O object and then yield the
20 /// object itself.
21 ///
22 /// This function will consume the object provided if an error happens, and
23 /// otherwise it will repeatedly call `flush` until it sees `Ok(())`, scheduling
24 /// a retry if `WouldBlock` is seen along the way.
flush<A>(a: A) -> Flush<A> where A: AsyncWrite,25 pub fn flush<A>(a: A) -> Flush<A>
26 where
27     A: AsyncWrite,
28 {
29     Flush { a: Some(a) }
30 }
31 
32 impl<A> Future for Flush<A>
33 where
34     A: AsyncWrite,
35 {
36     type Item = A;
37     type Error = io::Error;
38 
poll(&mut self) -> Poll<A, io::Error>39     fn poll(&mut self) -> Poll<A, io::Error> {
40         try_ready!(self.a.as_mut().unwrap().poll_flush());
41         Ok(Async::Ready(self.a.take().unwrap()))
42     }
43 }
44