aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2021-05-26 23:34:03 -0700
committerFuwn <[email protected]>2021-05-26 23:34:03 -0700
commitfca71ccccab25645de00406bd88d6132941f35dc (patch)
tree416ad62d129d5a27218fed3d3662b9cda28ac13d
parentdocs(crates): clarify that whirl_db is unimplemented (diff)
downloadwhirl-fca71ccccab25645de00406bd88d6132941f35dc.tar.xz
whirl-fca71ccccab25645de00406bd88d6132941f35dc.zip
refactor(global): move thread creation to respective crates
-rw-r--r--crates/whirl/src/cli.rs30
-rw-r--r--crates/whirl_api/Cargo.toml4
-rw-r--r--crates/whirl_api/src/lib.rs15
-rw-r--r--crates/whirl_server/src/lib.rs23
4 files changed, 42 insertions, 30 deletions
diff --git a/crates/whirl/src/cli.rs b/crates/whirl/src/cli.rs
index 05850d6..9236659 100644
--- a/crates/whirl/src/cli.rs
+++ b/crates/whirl/src/cli.rs
@@ -3,12 +3,6 @@
use structopt::clap::{App, AppSettings, Arg, SubCommand};
use whirl_config::Config;
-use whirl_server::{
- distributor::Distributor,
- hub::Hub,
- Server,
- ServerType::{AutoServer, RoomServer},
-};
pub struct Cli;
impl Cli {
@@ -70,27 +64,7 @@ impl Cli {
}
async fn run() {
- let (tx, _rx) = std::sync::mpsc::channel();
-
- let _threads = vec![
- tokio::spawn(async move {
- let _ = Distributor::listen(
- &*format!("0.0.0.0:{}", Config::get().distributor.port),
- AutoServer,
- )
- .await;
- }),
- tokio::spawn(async move {
- let _ = Hub::listen(&*format!("0.0.0.0:{}", Config::get().hub.port), RoomServer).await;
- }),
- tokio::spawn(async move {
- let _ = whirl_api::Api::listen(
- tx,
- &*format!("0.0.0.0:{}", Config::get().whirlsplash.api.port),
- )
- .await;
- }),
- ];
+ vec![whirl_api::make()].extend(whirl_server::make());
if std::env::var("DISABLE_PROMPT").unwrap_or_else(|_| "false".to_string()) == "true"
|| !Config::get().whirlsplash.prompt.enable
@@ -102,7 +76,5 @@ impl Cli {
} else {
whirl_prompt::Prompt::handle().await;
}
-
- // actix_web::rt::System::new("").block_on(rx.recv().unwrap().stop(true));
}
}
diff --git a/crates/whirl_api/Cargo.toml b/crates/whirl_api/Cargo.toml
index 3ce7ba3..315b7ae 100644
--- a/crates/whirl_api/Cargo.toml
+++ b/crates/whirl_api/Cargo.toml
@@ -21,6 +21,7 @@ actix-cors = "0.5.4"
# Utility
sysinfo = "0.18.0"
whirl_common = { path = "../whirl_common" }
+tokio = { version = "1.6.0", features = ["full"] }
# Serialization
serde = "1.0.126"
@@ -28,3 +29,6 @@ serde_derive = "1.0.126"
# Logging
log = "0.4.14"
+
+# Config
+whirl_config = { path = "../whirl_config" }
diff --git a/crates/whirl_api/src/lib.rs b/crates/whirl_api/src/lib.rs
index 3ab6cd8..d2f7811 100644
--- a/crates/whirl_api/src/lib.rs
+++ b/crates/whirl_api/src/lib.rs
@@ -47,3 +47,18 @@ impl Api {
sys.block_on(server)
}
}
+
+pub fn make() -> tokio::task::JoinHandle<()> {
+ // actix_web::rt::System::new("").block_on(rx.recv().unwrap().stop(true));
+
+ tokio::spawn(async move {
+ let _ = crate::Api::listen(
+ std::sync::mpsc::channel().0,
+ &*format!(
+ "0.0.0.0:{}",
+ whirl_config::Config::get().whirlsplash.api.port
+ ),
+ )
+ .await;
+ })
+}
diff --git a/crates/whirl_server/src/lib.rs b/crates/whirl_server/src/lib.rs
index a5efc24..1a00c61 100644
--- a/crates/whirl_server/src/lib.rs
+++ b/crates/whirl_server/src/lib.rs
@@ -33,8 +33,14 @@ use tokio::{
net::{TcpListener, TcpStream},
sync::Mutex,
};
+use whirl_config::Config;
-use crate::interaction::shared::Shared;
+use crate::{
+ distributor::Distributor,
+ hub::Hub,
+ interaction::shared::Shared,
+ ServerType::{AutoServer, RoomServer},
+};
/// The type of server the `listen` method of the `Server` trait will
/// implemented for.
@@ -92,3 +98,18 @@ pub trait Server {
count: usize,
) -> Result<(), Box<dyn Error>>;
}
+
+pub fn make() -> Vec<tokio::task::JoinHandle<()>> {
+ vec![
+ tokio::spawn(async move {
+ let _ = Distributor::listen(
+ &*format!("0.0.0.0:{}", Config::get().distributor.port),
+ AutoServer,
+ )
+ .await;
+ }),
+ tokio::spawn(async move {
+ let _ = Hub::listen(&*format!("0.0.0.0:{}", Config::get().hub.port), RoomServer).await;
+ }),
+ ]
+}