remove threadpool deps

pull/9932/head
Lee ByeongJun 8 months ago
parent 3d4889ce9a
commit 513946aabd

10
Cargo.lock generated

@ -1302,7 +1302,6 @@ dependencies = [
"once_cell", "once_cell",
"serde", "serde",
"tempfile", "tempfile",
"threadpool",
"toml", "toml",
"tree-sitter", "tree-sitter",
] ]
@ -2270,15 +2269,6 @@ dependencies = [
"syn 2.0.48", "syn 2.0.48",
] ]
[[package]]
name = "threadpool"
version = "1.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d050e60b33d41c19108b32cea32164033a9013fe3b46cbd4457559bfbf77afaa"
dependencies = [
"num_cpus",
]
[[package]] [[package]]
name = "time" name = "time"
version = "0.3.23" version = "0.3.23"

@ -29,7 +29,6 @@ log = "0.4"
# cloning/compiling tree-sitter grammars # cloning/compiling tree-sitter grammars
cc = { version = "1" } cc = { version = "1" }
threadpool = { version = "1.0" }
tempfile = "3.10.1" tempfile = "3.10.1"
dunce = "1.0.4" dunce = "1.0.4"

@ -1,6 +1,5 @@
use anyhow::{anyhow, bail, Context, Result}; use anyhow::{anyhow, bail, Context, Result};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::fs;
use std::time::SystemTime; use std::time::SystemTime;
use std::{ use std::{
collections::HashSet, collections::HashSet,
@ -8,6 +7,7 @@ use std::{
process::Command, process::Command,
sync::mpsc::channel, sync::mpsc::channel,
}; };
use std::{fs, thread};
use tempfile::TempPath; use tempfile::TempPath;
use tree_sitter::Language; use tree_sitter::Language;
@ -225,25 +225,28 @@ where
F: Fn(GrammarConfiguration) -> Result<Res> + Send + 'static + Clone, F: Fn(GrammarConfiguration) -> Result<Res> + Send + 'static + Clone,
Res: Send + 'static, Res: Send + 'static,
{ {
let pool = threadpool::Builder::new().build();
let (tx, rx) = channel(); let (tx, rx) = channel();
let mut handles = Vec::new();
for grammar in grammars { for grammar in grammars {
let tx = tx.clone(); let tx = tx.to_owned();
let job = job.clone(); let job = job.to_owned();
pool.execute(move || { let handle = thread::spawn(move || {
// Ignore any SendErrors, if any job in another thread has encountered an let result = (grammar.grammar_id.to_owned(), job(grammar));
// error the Receiver will be closed causing this send to fail. let _ = tx.send(result);
let _ = tx.send((grammar.grammar_id.clone(), job(grammar)));
}); });
handles.push(handle);
} }
drop(tx); for handle in handles {
handle.join().unwrap();
}
drop(tx);
rx.iter().collect() rx.iter().collect()
} }
enum FetchStatus { enum FetchStatus {
GitUpToDate, GitUpToDate,
GitUpdated { revision: String }, GitUpdated { revision: String },

Loading…
Cancel
Save