From 490c6a6e8beaac435b552bda8fa04e4c21729519 Mon Sep 17 00:00:00 2001 From: Michael Aaron Murphy Date: Tue, 17 Aug 2021 00:20:04 +0200 Subject: [PATCH] fix(scripts): MPMC channel causing deadlock --- plugins/src/scripts/mod.rs | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/plugins/src/scripts/mod.rs b/plugins/src/scripts/mod.rs index 2145177..04083f7 100644 --- a/plugins/src/scripts/mod.rs +++ b/plugins/src/scripts/mod.rs @@ -3,6 +3,7 @@ use pop_launcher::*; use flume::Sender; use futures_lite::{AsyncBufReadExt, StreamExt}; +use std::collections::VecDeque; use std::os::unix::process::CommandExt; use std::{ io, @@ -23,7 +24,7 @@ pub async fn main() { while let Some(result) = requests.next().await { match result { - Ok(response) => match response { + Ok(request) => match request { Request::Activate(id) => app.activate(id).await, Request::Search(query) => app.search(&query).await, Request::Exit => break, @@ -72,23 +73,21 @@ impl App { } async fn reload(&mut self) { - let (path_tx, path_rx) = flume::unbounded::(); + let (tx, rx) = flume::unbounded::(); - #[allow(deprecated)] - let _ = path_tx.send( + let mut queue = VecDeque::new(); + + queue.push_back( std::env::home_dir() .expect("user does not have home dir") .join(LOCAL_PATH), ); - - let _ = path_tx.send(Path::new(SYSTEM_ADMIN_PATH).to_owned()); - let _ = path_tx.send(Path::new(DISTRIBUTION_PATH).to_owned()); - - let (tx, rx) = flume::unbounded::(); + queue.push_back(Path::new(SYSTEM_ADMIN_PATH).to_owned()); + queue.push_back(Path::new(DISTRIBUTION_PATH).to_owned()); let script_sender = async move { - while let Ok(path) = path_rx.recv_async().await { - load_from(&path, &path_tx, tx.clone()).await; + while let Some(path) = queue.pop_front() { + load_from(&path, &mut queue, tx.clone()).await; } }; @@ -146,14 +145,14 @@ struct ScriptInfo { description: String, } -async fn load_from(path: &Path, path_tx: &Sender, tx: Sender) { +async fn load_from(path: &Path, paths: &mut VecDeque, tx: Sender) { if let Ok(directory) = path.read_dir() { for entry in directory.filter_map(Result::ok) { let tx = tx.clone(); let path = entry.path(); if path.is_dir() { - path_tx.send_async(path); + paths.push_back(path); continue; }