Skip to content

Commit

Permalink
feat(server): impl Sink for Body::Sender
Browse files Browse the repository at this point in the history
Closes #1781
  • Loading branch information
jxs authored and seanmonstar committed Apr 10, 2019
1 parent 0f33354 commit 8d70bac
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/body/body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::fmt;

use bytes::Bytes;
use futures::sync::{mpsc, oneshot};
use futures::{Async, Future, Poll, Stream};
use futures::{Async, Future, Poll, Stream, Sink, AsyncSink, StartSend};
use h2;
use http::HeaderMap;

Expand Down Expand Up @@ -381,6 +381,25 @@ impl Sender {
}
}

impl Sink for Sender {
type SinkItem = Chunk;
type SinkError = ::Error;

fn poll_complete(&mut self) -> Poll<(), Self::SinkError> {
Ok(Async::Ready(()))
}

fn start_send(&mut self, msg: Chunk) -> StartSend<Self::SinkItem, Self::SinkError> {
match self.poll_ready()? {
Async::Ready(_) => {
self.send_data(msg).map_err(|_| ::Error::new_closed())?;
Ok(AsyncSink::Ready)
}
Async::NotReady => Ok(AsyncSink::NotReady(msg)),
}
}
}

impl From<Chunk> for Body {
#[inline]
fn from(chunk: Chunk) -> Body {
Expand Down

0 comments on commit 8d70bac

Please sign in to comment.