feat(transport): Add serve_with_incoming_shutdown (#220)
This commit is contained in:
@@ -388,12 +388,12 @@ where
|
|||||||
pub async fn serve_with_shutdown<F: Future<Output = ()>>(
|
pub async fn serve_with_shutdown<F: Future<Output = ()>>(
|
||||||
self,
|
self,
|
||||||
addr: SocketAddr,
|
addr: SocketAddr,
|
||||||
f: F,
|
signal: F,
|
||||||
) -> Result<(), super::Error> {
|
) -> Result<(), super::Error> {
|
||||||
let incoming = TcpIncoming::new(addr, self.server.tcp_nodelay, self.server.tcp_keepalive)
|
let incoming = TcpIncoming::new(addr, self.server.tcp_nodelay, self.server.tcp_keepalive)
|
||||||
.map_err(super::Error::from_source)?;
|
.map_err(super::Error::from_source)?;
|
||||||
self.server
|
self.server
|
||||||
.serve_with_shutdown(self.routes, incoming, Some(f))
|
.serve_with_shutdown(self.routes, incoming, Some(signal))
|
||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -411,6 +411,28 @@ where
|
|||||||
.serve_with_shutdown::<_, _, future::Ready<()>, _, _>(self.routes, incoming, None)
|
.serve_with_shutdown::<_, _, future::Ready<()>, _, _>(self.routes, incoming, None)
|
||||||
.await
|
.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 {
|
impl fmt::Debug for Server {
|
||||||
|
|||||||
Reference in New Issue
Block a user