refactor: Replace postage with flume

This commit is contained in:
Michael Aaron Murphy 2022-03-27 16:02:25 +02:00 committed by Michael Murphy
parent 805bf6333e
commit e578f2d19c
11 changed files with 192 additions and 112 deletions

View file

@ -4,9 +4,8 @@
use crate::*;
use pop_launcher::*;
use flume::Sender;
use futures_lite::{AsyncBufReadExt, StreamExt};
use postage::mpsc::Sender;
use postage::prelude::*;
use smol::process::{Command, Stdio};
use std::collections::VecDeque;
use std::{
@ -69,7 +68,7 @@ impl App {
}
async fn reload(&mut self) {
let (tx, mut rx) = postage::mpsc::channel::<ScriptInfo>(8);
let (tx, rx) = flume::bounded::<ScriptInfo>(8);
let mut queue = VecDeque::new();
@ -88,7 +87,7 @@ impl App {
};
let script_receiver = async {
'outer: while let Some(script) = rx.recv().await {
'outer: while let Ok(script) = rx.recv_async().await {
tracing::debug!("appending script: {:?}", script);
for cached_script in &self.scripts {
if cached_script.name == script.name {
@ -149,7 +148,7 @@ struct ScriptInfo {
async fn load_from(path: &Path, paths: &mut VecDeque<PathBuf>, tx: Sender<ScriptInfo>) {
if let Ok(directory) = path.read_dir() {
for entry in directory.filter_map(Result::ok) {
let mut tx = tx.clone();
let tx = tx.clone();
let path = entry.path();
if path.is_dir() {
@ -200,7 +199,7 @@ async fn load_from(path: &Path, paths: &mut VecDeque<PathBuf>, tx: Sender<Script
}
}
let _ = tx.send(info).await;
let _ = tx.send_async(info).await;
})
.detach();
}