diff --git a/src/bridge/mod.rs b/src/bridge/mod.rs index 6608347..3dec52c 100644 --- a/src/bridge/mod.rs +++ b/src/bridge/mod.rs @@ -54,24 +54,6 @@ async fn drain(receiver: &mut UnboundedReceiver) -> Option, nvim: &Neovim>) -> bool { - if let Some(commands) = drain(receiver).await { - let (resize_list, other_commands): (Vec, Vec) = commands - .into_iter() - .partition(|command| command.is_resize()); - if let Some(resize_command) = resize_list.into_iter().last() { - resize_command.execute(&nvim).await; - } - - for ui_command in other_commands.into_iter() { - ui_command.execute(&nvim).await; - } - true - } else { - false - } -} - async fn start_process(mut receiver: UnboundedReceiver) { let (width, height) = INITIAL_DIMENSIONS; let (mut nvim, io_handler, _) = create::new_child_cmd(&mut create_nvim_command(), NeovimHandler::new()).await @@ -97,7 +79,29 @@ async fn start_process(mut receiver: UnboundedReceiver) { let nvim = Arc::new(nvim); tokio::spawn(async move { loop { - if !handle_current_commands(&mut receiver, &nvim).await { + if let Some(commands) = drain(&mut receiver).await { + let (resize_list, other_commands): (Vec, Vec) = commands + .into_iter() + .partition(|command| command.is_resize()); + + for command in resize_list + .into_iter().last().into_iter() + .chain(other_commands.into_iter()) { + + let nvim = nvim.clone(); + tokio::spawn(async move { + command.execute(&nvim).await; + }); + } + // resize_list.into_iter().last().map(|resize_command| tokio::spawn() + // if let Some(resize_command) = { + // tokio::spawn(resize_command.execute(&nvim)); + // } + + // for ui_command in other_commands.into_iter() { + // tokio::spawn(ui_command.execute(&nvim)); + // } + } else { break; } } @@ -114,7 +118,7 @@ impl Bridge { let mut runtime = Runtime::new().unwrap(); let (sender, receiver) = unbounded_channel::(); - runtime.block_on(async move { + runtime.spawn(async move { start_process(receiver).await; });