blob: a035a2601e1719b5ae94b75a8a485c166f26e9c9 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
use crate::state::{State, StatePhase};
use ipc_channel::ipc::IpcSender;
use log::*;
use mumlib::command::{Command, CommandResponse};
use std::sync::{Arc, Mutex};
use tokio::sync::mpsc;
pub async fn handle(
state: Arc<Mutex<State>>,
mut command_receiver: mpsc::UnboundedReceiver<(
Command,
IpcSender<mumlib::error::Result<Option<CommandResponse>>>,
)>,
) {
debug!("Begin listening for commands");
while let Some(command) = command_receiver.recv().await {
debug!("Received command {:?}", command.0);
let mut state = state.lock().unwrap();
let (wait_for_connected, command_response) = state.handle_command(command.0).await;
if wait_for_connected {
let mut watcher = state.phase_receiver();
drop(state);
while !matches!(watcher.recv().await.unwrap(), StatePhase::Connected) {}
}
command.1.send(command_response).unwrap();
}
//TODO err if not connected
//while let Some(command) = command_receiver.recv().await {
// debug!("Parsing command {:?}", command);
//}
//debug!("Finished handling commands");
}
|