diff options
| author | Fuwn <[email protected]> | 2021-06-08 02:20:01 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2021-06-08 02:20:01 -0700 |
| commit | 1487687ca93abfab68f701b5df26b342aa8c1ed1 (patch) | |
| tree | f4bb983060f549419e9c6b77e2501159867e2169 /crates/whirl_server/src | |
| parent | refactor(docker): docker compose! (diff) | |
| download | whirl-1487687ca93abfab68f701b5df26b342aa8c1ed1.tar.xz whirl-1487687ca93abfab68f701b5df26b342aa8c1ed1.zip | |
feat(whirl_server): conditional sub-server spawning
Diffstat (limited to 'crates/whirl_server/src')
| -rw-r--r-- | crates/whirl_server/src/lib.rs | 46 |
1 files changed, 34 insertions, 12 deletions
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()] } } |