Skip to content

Commit

Permalink
Bind a console server to tonic without spawning a server
Browse files Browse the repository at this point in the history
  • Loading branch information
maximelenoir authored May 24, 2023
1 parent 2617504 commit 700b80a
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions console-subscriber/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use tokio::net::UnixListener;
use tokio::sync::{mpsc, oneshot};
#[cfg(unix)]
use tokio_stream::wrappers::UnixListenerStream;
use tonic::transport::server::Router;
use tracing_core::{
span::{self, Id},
subscriber::{self, Subscriber},
Expand Down Expand Up @@ -988,6 +989,19 @@ impl Server {
aggregate.abort();
res?.map_err(Into::into)
}

/// Starts the aggregator and set-up the [`tonic`] gRPC transport server `builder`.
///
/// [`tonic`]: https://docs.rs/tonic/
pub fn bind(mut self, mut builder: tonic::transport::Server) -> Router {
let aggregate = self
.aggregator
.take()
.expect("cannot start server multiple times");
let _ = spawn_named(aggregate.run(), "console::aggregate");
let srv = proto::instrument::instrument_server::InstrumentServer::new(self);
builder.add_service(srv)
}
}

#[tonic::async_trait]
Expand Down

0 comments on commit 700b80a

Please sign in to comment.