diff options
| -rw-r--r-- | crates/whirl/src/cli.rs | 2 | ||||
| -rw-r--r-- | crates/whirl_server/src/lib.rs | 46 |
2 files changed, 35 insertions, 13 deletions
diff --git a/crates/whirl/src/cli.rs b/crates/whirl/src/cli.rs index 54ce142..d7a65ce 100644 --- a/crates/whirl/src/cli.rs +++ b/crates/whirl/src/cli.rs @@ -66,7 +66,7 @@ impl Cli { } async fn run() { - vec![whirl_api::make()].extend(whirl_server::make()); + vec![whirl_api::make()].extend(whirl_server::make::all()); if std::env::var("DISABLE_PROMPT").unwrap_or_else(|_| "false".to_string()) == "true" || !Config::get().whirlsplash.prompt.enable diff --git a/crates/whirl_server/src/lib.rs b/crates/whirl_server/src/lib.rs index 9fae5ad..77a2cee 100644 --- a/crates/whirl_server/src/lib.rs +++ b/crates/whirl_server/src/lib.rs @@ -40,7 +40,6 @@ use tokio::{ net::{TcpListener, TcpStream}, sync::Mutex, }; -use whirl_config::Config; use crate::interaction::shared::Shared; @@ -101,14 +100,19 @@ pub trait Server { ) -> Result<(), Box<dyn Error>>; } -/// Spawn and return a vector of thread handles for each sub-server — which -/// should be — instantiated by the `whirl_server` crate. -/// -/// # Panics -/// - A panic may occur if the TCP server is unable to bind the specified port. -#[must_use] -pub fn make() -> Vec<tokio::task::JoinHandle<()>> { - vec![ +pub mod make { + use tokio::task::JoinHandle; + use whirl_config::Config; + + use crate::{Server, ServerType}; + + /// Spawn and return a thread handle for a Distributor sub-server. + /// + /// # Panics + /// - A panic may occur if the TCP server is unable to bind the specified + /// port. + #[must_use] + pub fn distributor() -> JoinHandle<()> { tokio::spawn(async move { crate::distributor::Distributor::listen( &*format!("0.0.0.0:{}", Config::get().distributor.port), @@ -116,7 +120,16 @@ pub fn make() -> Vec<tokio::task::JoinHandle<()>> { ) .await .unwrap(); - }), + }) + } + + /// Spawn and return a thread handle for a Hub sub-server. + /// + /// # Panics + /// - A panic may occur if the TCP server is unable to bind the specified + /// port. + #[must_use] + pub fn hub() -> JoinHandle<()> { tokio::spawn(async move { crate::hub::Hub::listen( &*format!("0.0.0.0:{}", Config::get().hub.port), @@ -124,6 +137,15 @@ pub fn make() -> Vec<tokio::task::JoinHandle<()>> { ) .await .unwrap(); - }), - ] + }) + } + + /// Spawn and return a vector of thread handles for each sub-server — which + /// should be — instantiated by the `whirl_server` crate. + /// + /// # Panics + /// - A panic may occur if the TCP server is unable to bind the specified + /// port. + #[must_use] + pub fn all() -> Vec<JoinHandle<()>> { vec![distributor(), hub()] } } |