From 503f6c90395682bf5d7fd3fb8a79bfcfc3c2f329 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gustav=20S=C3=B6rn=C3=A4s?= Date: Tue, 13 Oct 2020 17:05:22 +0200 Subject: wait for complete state before sending commands --- mumd/src/command.rs | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'mumd/src/command.rs') diff --git a/mumd/src/command.rs b/mumd/src/command.rs index 322bde8..1f7a781 100644 --- a/mumd/src/command.rs +++ b/mumd/src/command.rs @@ -1,3 +1,9 @@ +use crate::state::State; + +use std::sync::{Arc, Mutex}; +use tokio::sync::mpsc; + +#[derive(Debug)] pub enum Command { ChannelJoin { channel_id: u32, @@ -12,3 +18,16 @@ pub enum Command { ServerDisconnect, Status, } + +pub async fn handle( + state: Arc>, + mut command_receiver: mpsc::UnboundedReceiver, +) { + // wait until we can send packages + let mut initialized_receiver = state.lock().unwrap().initialized_receiver(); + while matches!(initialized_receiver.recv().await, Some(false)) {} + + while let Some(command) = command_receiver.recv().await { + state.lock().unwrap().handle_command(command).await; + } +} -- cgit v1.2.1