futures_util/io/
flush.rs

1use std::io;
2
3use {Poll, Future, Async, task};
4
5use futures_io::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)]
15pub struct Flush<A> {
16    a: Option<A>,
17}
18
19pub fn flush<A>(a: A) -> Flush<A>
20    where A: AsyncWrite,
21{
22    Flush {
23        a: Some(a),
24    }
25}
26
27impl<A> Future for Flush<A>
28    where A: AsyncWrite,
29{
30    type Item = A;
31    type Error = io::Error;
32
33    fn poll(&mut self, cx: &mut task::Context) -> Poll<A, io::Error> {
34        try_ready!(self.a.as_mut().unwrap().poll_flush(cx));
35        Ok(Async::Ready(self.a.take().unwrap()))
36    }
37}
38