Skip to main content

rs_zero/rpc/
server.rs

1use std::{future::Future, net::SocketAddr};
2
3/// Starts a tonic health server with graceful shutdown.
4///
5/// This helper gives the MVP a concrete, generated tonic service without
6/// requiring application projects to define protobuf files immediately.
7pub async fn serve_health_with_shutdown<F>(
8    addr: SocketAddr,
9    shutdown: F,
10) -> Result<(), tonic::transport::Error>
11where
12    F: Future<Output = ()> + Send + 'static,
13{
14    let (_reporter, health_service) = tonic_health::server::health_reporter();
15
16    tonic::transport::Server::builder()
17        .add_service(health_service)
18        .serve_with_shutdown(addr, shutdown)
19        .await
20}