use std::process::{Command, Stdio};
use std::sync::mpsc::SyncSender;
-fn rustfmt(src: &Path, rustfmt: &Path, paths: &[PathBuf], check: bool) -> Box<impl FnMut()> {
+fn rustfmt(src: &Path, rustfmt: &Path, paths: &[PathBuf], check: bool) -> impl FnMut() {
let mut cmd = Command::new(&rustfmt);
// avoid the submodule config paths from coming into play,
// we only allow a single global config for the workspace for now
cmd.args(paths);
let cmd_debug = format!("{:?}", cmd);
let mut cmd = cmd.spawn().expect("running rustfmt");
- // poor man's async: return a box that'll wait for rustfmt's completion
- Box::new(move || {
+ // poor man's async: return a closure that'll wait for rustfmt's completion
+ move || {
let status = cmd.wait().unwrap();
if !status.success() {
eprintln!(
);
std::process::exit(1);
}
- })
+ }
}
#[derive(serde::Deserialize)]
WalkBuilder::new(src.clone()).types(matcher).overrides(ignore_fmt).build_parallel();
// there is a lot of blocking involved in spawning a child process and reading files to format.
- // spawn more processes than available cores to keep the CPU busy
- let max_processes = num_cpus::get() * 2;
+ // spawn more processes than available concurrency to keep the CPU busy
+ let max_processes = build.jobs() as usize * 2;
// spawn child processes on a separate thread so we can batch entries we have received from ignore
let thread = std::thread::spawn(move || {
let child = rustfmt(&src, &rustfmt_path, paths.as_slice(), check);
children.push_back(child);
- if children.len() > max_processes {
+ if children.len() >= max_processes {
// await oldest child
children.pop_front().unwrap()();
}