From a3c393a711c71698ef833f1923374798cbb0d0b4 Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Wed, 14 Oct 2020 02:04:16 +0200 Subject: fix code so that it doesn't deadlock --- mumd/src/command.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'mumd/src/command.rs') diff --git a/mumd/src/command.rs b/mumd/src/command.rs index c3b72bf..8a5c715 100644 --- a/mumd/src/command.rs +++ b/mumd/src/command.rs @@ -1,8 +1,9 @@ -use crate::state::{Channel, Server, State}; +use crate::state::{Channel, Server, State, StatePhase}; use std::collections::HashMap; use std::sync::{Arc, Mutex}; use tokio::sync::mpsc; +use log::*; #[derive(Debug)] pub enum Command { @@ -38,6 +39,13 @@ pub async fn handle( ) { //TODO err if not connected while let Some(command) = command_receiver.recv().await { - state.lock().unwrap().handle_command(command).await; + debug!("Parsing command {:?}", command); + let mut state = state.lock().unwrap(); + let (wait_for_connected, _) = state.handle_command(command).await; + if wait_for_connected { + let mut watcher = state.phase_receiver(); + drop(state); + while !matches!(watcher.recv().await.unwrap(), StatePhase::Connected) {} + } } } -- cgit v1.2.1