1use std::io;
2
3use futures::{Future, Poll, Async};
4use tokio_io::AsyncWrite;
5
6use {IoBuf};
7
8pub struct Flushed<S>(Option<IoBuf<S>>);
11
12
13impl<S: AsyncWrite> Future for Flushed<S> {
14 type Item = IoBuf<S>;
15 type Error = io::Error;
16 fn poll(&mut self) -> Poll<IoBuf<S>, io::Error> {
17 if let Some(ref mut conn) = self.0 {
18 conn.flush()?;
19 if conn.out_buf.len() > 0 && !conn.done() {
20 return Ok(Async::NotReady);
21 }
22 }
23 Ok(Async::Ready(self.0.take().unwrap()))
24 }
25}
26
27pub fn flushed<S: AsyncWrite>(sock: IoBuf<S>) -> Flushed<S> {
28 Flushed(Some(sock))
29}