Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove threadpool deps #90

Merged
merged 1 commit into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
22 changes: 13 additions & 9 deletions src/grammar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
// 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,
path::{Path, PathBuf},
process::Command,
sync::mpsc::channel,
};
use std::{fs, thread};
use tempfile::TempPath;
use tree_sitter::Language;

Expand Down Expand Up @@ -218,22 +218,26 @@ where
F: Fn(GrammarConfiguration) -> Result<Res> + 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()
}

Expand Down
Loading