Skip to content

Commit 8d70bac

Browse files
jxsseanmonstar
authored andcommitted
feat(server): impl Sink for Body::Sender
Closes #1781
1 parent 0f33354 commit 8d70bac

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/body/body.rs

+20-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::fmt;
33

44
use bytes::Bytes;
55
use futures::sync::{mpsc, oneshot};
6-
use futures::{Async, Future, Poll, Stream};
6+
use futures::{Async, Future, Poll, Stream, Sink, AsyncSink, StartSend};
77
use h2;
88
use http::HeaderMap;
99

@@ -381,6 +381,25 @@ impl Sender {
381381
}
382382
}
383383

384+
impl Sink for Sender {
385+
type SinkItem = Chunk;
386+
type SinkError = ::Error;
387+
388+
fn poll_complete(&mut self) -> Poll<(), Self::SinkError> {
389+
Ok(Async::Ready(()))
390+
}
391+
392+
fn start_send(&mut self, msg: Chunk) -> StartSend<Self::SinkItem, Self::SinkError> {
393+
match self.poll_ready()? {
394+
Async::Ready(_) => {
395+
self.send_data(msg).map_err(|_| ::Error::new_closed())?;
396+
Ok(AsyncSink::Ready)
397+
}
398+
Async::NotReady => Ok(AsyncSink::NotReady(msg)),
399+
}
400+
}
401+
}
402+
384403
impl From<Chunk> for Body {
385404
#[inline]
386405
fn from(chunk: Chunk) -> Body {

0 commit comments

Comments
 (0)