Skip to content

Commit

Permalink
feat(transport): Add serve_with_incoming_shutdown (#220)
Browse files Browse the repository at this point in the history
  • Loading branch information
LucioFranco authored Jan 8, 2020
1 parent faa26ac commit a66595b
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions tonic/src/transport/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,12 +388,12 @@ where
pub async fn serve_with_shutdown<F: Future<Output = ()>>(
self,
addr: SocketAddr,
f: F,
signal: F,
) -> Result<(), super::Error> {
let incoming = TcpIncoming::new(addr, self.server.tcp_nodelay, self.server.tcp_keepalive)
.map_err(super::Error::from_source)?;
self.server
.serve_with_shutdown(self.routes, incoming, Some(f))
.serve_with_shutdown(self.routes, incoming, Some(signal))
.await
}

Expand All @@ -411,6 +411,28 @@ where
.serve_with_shutdown::<_, _, future::Ready<()>, _, _>(self.routes, incoming, None)
.await
}

/// Consume this [`Server`] creating a future that will execute the server on
/// the provided incoming stream of `AsyncRead + AsyncWrite`. Similar to
/// `serve_with_shutdown` this method will also take a signal future to
/// gracefully shutdown the server.
///
/// [`Server`]: struct.Server.html
pub async fn serve_with_incoming_shutdown<I, IO, IE, F>(
self,
incoming: I,
signal: F,
) -> Result<(), super::Error>
where
I: Stream<Item = Result<IO, IE>>,
IO: AsyncRead + AsyncWrite + Connected + Unpin + Send + 'static,
IE: Into<crate::Error>,
F: Future<Output = ()>,
{
self.server
.serve_with_shutdown(self.routes, incoming, Some(signal))
.await
}
}

impl fmt::Debug for Server {
Expand Down

0 comments on commit a66595b

Please sign in to comment.