multi_rpc/runner.rs
1use std::io;
2
3use tokio::task::JoinHandle;
4
5/// Manages the spawned server tasks, waiting for a shutdown signal to terminate them.
6pub struct ServerRunner {
7 pub(crate) handles: Vec<JoinHandle<()>>,
8}
9
10impl ServerRunner {
11 /// Runs all configured servers and blocks the current task until a shutdown
12 /// signal (Ctrl+C) is received.
13 ///
14 /// Upon receiving the signal, it aborts all spawned server tasks.
15 pub async fn run(self) -> io::Result<()> {
16 println!("✅ Servers running. Press Ctrl+C to shut down.");
17 tokio::signal::ctrl_c().await?;
18
19 println!("\nShutdown signal received. Aborting server tasks...");
20 for handle in self.handles {
21 handle.abort();
22 }
23
24 Ok(())
25 }
26}