allow multi-threading again
This commit is contained in:
parent
c8375d1b15
commit
c01442b11c
3 changed files with 12 additions and 9 deletions
|
@ -393,6 +393,10 @@ impl GameHandler {
|
|||
let tx = self.state.broadcast_tx.clone();
|
||||
let active_games = self.games.len();
|
||||
let msg = to_string(&ServerActiveGames { active_games }).unwrap();
|
||||
tokio::spawn(async move { tx.send(msg) });
|
||||
tokio::spawn(async move {
|
||||
if let Err(e) = tx.send(msg) {
|
||||
tracing::error!("Error broadcasting game count: {}", e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,8 +18,8 @@ use tower_http::{compression::CompressionLayer, services::ServeDir};
|
|||
use tracing_subscriber::prelude::*;
|
||||
use user_handler::UserHandler;
|
||||
|
||||
#[tokio::main(flavor = "current_thread")]
|
||||
// #[tokio::main]
|
||||
// #[tokio::main(flavor = "current_thread")]
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
// stuff for logging
|
||||
tracing_subscriber::registry()
|
||||
|
@ -29,7 +29,7 @@ async fn main() -> Result<()> {
|
|||
// "server=trace,tower_http=trace,lib=trace,tokio=trace,runtime=trace".into()
|
||||
}),
|
||||
)
|
||||
// .with(console_subscriber::ConsoleLayer::builder().spawn())
|
||||
.with(console_subscriber::ConsoleLayer::builder().spawn())
|
||||
.with(tracing_subscriber::fmt::layer())
|
||||
.init();
|
||||
|
||||
|
@ -68,10 +68,10 @@ async fn main() -> Result<()> {
|
|||
});
|
||||
|
||||
// Set up state
|
||||
let (broadcast_tx, _rx) = broadcast::channel(1000000);
|
||||
let (users_tx, mut users_rx) = mpsc::channel(1000000);
|
||||
let (messages_tx, mut messages_rx) = mpsc::channel(1000000);
|
||||
let (games_tx, mut games_rx) = mpsc::channel(1000000);
|
||||
let (broadcast_tx, _rx) = broadcast::channel(1000);
|
||||
let (users_tx, mut users_rx) = mpsc::channel(1000);
|
||||
let (messages_tx, mut messages_rx) = mpsc::channel(1000);
|
||||
let (games_tx, mut games_rx) = mpsc::channel(1000);
|
||||
let first_names = load_names("data/first.txt")?;
|
||||
let last_names = load_names("data/last.txt")?;
|
||||
let reserved_names = RwLock::new(HashSet::<String>::new());
|
||||
|
|
|
@ -150,7 +150,6 @@ impl MessageHandler {
|
|||
|
||||
/// This runs when a connection closes
|
||||
fn handle_close(&self, close_frame: Option<CloseFrame>, addr: SocketAddr) {
|
||||
// TODO: this is user handler's job
|
||||
let msg = UserHandlerMessage::Cleanup(addr);
|
||||
let tx = self.state.users_tx.clone();
|
||||
tokio::spawn(async move { tx.send(msg).await });
|
||||
|
|
Loading…
Add table
Reference in a new issue