Skip to content

Commit

Permalink
Stop signal and shutdown node on Ctl-C
Browse files Browse the repository at this point in the history
  • Loading branch information
bennyhodl committed Dec 17, 2024
1 parent 1588263 commit 1d3e21a
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions ddk-node/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,18 @@ impl DdkNode {
let ddk: Ddk = builder.finish().await?;

ddk.start()?;

let node = DdkNode::new(ddk);

Server::builder()
let node_stop = node.node.clone();
let server = Server::builder()
.add_service(DdkRpcServer::new(node))
.serve(opts.grpc_host.parse()?)
.await?;
.serve_with_shutdown(opts.grpc_host.parse()?, async {
tokio::signal::ctrl_c()
.await
.expect("Failed to install Ctrl+C signal handler");
let _ = node_stop.stop();
});

server.await?;

Ok(())
}
Expand Down

0 comments on commit 1d3e21a

Please sign in to comment.