chord_dht/
server.rs

1use crate::core::error::*;
2use futures::future;
3
4pub struct ServerManager {
5	pub handle: future::JoinAll<tokio::task::JoinHandle<()>>,
6	pub tx: tokio::sync::watch::Sender<bool>
7}
8
9impl ServerManager {
10	/// Wait for the server to terminate
11	pub async fn wait(self) -> DhtResult<()> {
12		self.handle.await
13			.into_iter()
14			.collect::<Result<Vec<_>, tokio::task::JoinError>>()?;
15
16		Ok(())
17	}
18
19	/// Stop the server gracefully
20	pub async fn stop(self) -> DhtResult<()> {
21		self.tx.send(true)?;
22		self.wait().await
23	}
24}