Skip to content

Commit

Permalink
remove deps (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
notJoon authored Mar 19, 2024
1 parent ead19cc commit 9703f58
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 20 deletions.
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

0 comments on commit 9703f58

Please sign in to comment.