diff --git a/Cargo.lock b/Cargo.lock index a6ba2c6..b311d0d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -122,7 +122,6 @@ dependencies = [ "serde_json", "strsim 0.10.0", "tempfile", - "threadpool", "tokio", "toml", "tree-sitter", @@ -793,15 +792,6 @@ dependencies = [ "windows-sys 0.52.0", ] -[[package]] -name = "threadpool" -version = "1.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d050e60b33d41c19108b32cea32164033a9013fe3b46cbd4457559bfbf77afaa" -dependencies = [ - "num_cpus", -] - [[package]] name = "tinyvec" version = "1.6.0" diff --git a/Cargo.toml b/Cargo.toml index 4aa71e3..75ebbb0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,7 +23,6 @@ serde = { version = "1.0", features = ["derive"] } serde_json = "1.0.104" strsim = "0.10.0" tempfile = "3.8.0" -threadpool = "1.8.1" tokio = { version = "1.32.0", features = ["full"] } toml = "0.7.4" tree-sitter = "0.20.10" diff --git a/src/grammar.rs b/src/grammar.rs index c9f6d8e..102cfc2 100644 --- a/src/grammar.rs +++ b/src/grammar.rs @@ -2,7 +2,6 @@ // https://github.com/helix-editor/helix/blob/master/helix-loader/src/grammar.rs use anyhow::{anyhow, bail, Context, Result}; use serde::{Deserialize, Serialize}; -use std::fs; use std::time::SystemTime; use std::{ collections::HashSet, @@ -10,6 +9,7 @@ use std::{ process::Command, sync::mpsc::channel, }; +use std::{fs, thread}; use tempfile::TempPath; use tree_sitter::Language; @@ -218,22 +218,26 @@ where F: Fn(GrammarConfiguration) -> Result + Send + 'static + Clone, Res: Send + 'static, { - let pool = threadpool::Builder::new().build(); let (tx, rx) = channel(); + let mut handles = Vec::new(); for grammar in grammars { - let tx = tx.clone(); - let job = job.clone(); + let tx = tx.to_owned(); + let job = job.to_owned(); - pool.execute(move || { - // Ignore any SendErrors, if any job in another thread has encountered an - // error the Receiver will be closed causing this send to fail. - let _ = tx.send((grammar.grammar_id.clone(), job(grammar))); + let handle = thread::spawn(move || { + let result = (grammar.grammar_id.clone(), job(grammar)); + let _ = tx.send(result); }); + + handles.push(handle); } - drop(tx); + for handle in handles { + let _ = handle.join(); + } + drop(tx); // not necessary, but makes it explicit that we're done with the sender rx.iter().collect() }