Skip to content

Commit 082e401

Browse files
WaffleLapkinNoratrieb
authored andcommitted
Run examples in parallel
1 parent 0aa47fb commit 082e401

File tree

1 file changed

+28
-12
lines changed

1 file changed

+28
-12
lines changed

builder/src/main.rs

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::path::Path;
1+
use std::{path::Path, thread};
22

33
use eyre::{Context, OptionExt};
44

@@ -11,19 +11,35 @@ fn main() -> eyre::Result<()> {
1111

1212
install_toolchain(&examples_dir).wrap_err("install toolchain")?;
1313

14-
for example in examples {
15-
let example = example.wrap_err("reading example dir entry")?;
16-
if example
17-
.file_type()
18-
.wrap_err("getting file type of entry")?
19-
.is_dir()
20-
{
21-
continue;
14+
thread::scope(|scope| {
15+
let mut handles = Vec::new();
16+
17+
for example in examples {
18+
handles.push(scope.spawn(|| {
19+
let example = example.wrap_err("reading example dir entry")?;
20+
if example
21+
.file_type()
22+
.wrap_err("getting file type of entry")?
23+
.is_dir()
24+
{
25+
return Ok(());
26+
}
27+
28+
run_example(&examples_dir, &example.file_name().to_str().unwrap())
29+
.wrap_err_with(|| format!("running {:?}", example.file_name()))
30+
}));
2231
}
2332

24-
run_example(&examples_dir, &example.file_name().to_str().unwrap())
25-
.wrap_err_with(|| format!("running {:?}", example.file_name()))?;
26-
}
33+
handles
34+
.into_iter()
35+
.map(|handle| {
36+
handle
37+
.join()
38+
.unwrap_or_else(|payload| std::panic::resume_unwind(payload))
39+
})
40+
.filter_map(|res| res.err())
41+
.for_each(|err| eprint!("error while running example: {err}"));
42+
});
2743

2844
Ok(())
2945
}

0 commit comments

Comments
 (0)