Expand description
Shared bounded-parallelism helper used by stages that run one subprocess per sub-config (makeself, nfpm, snapcraft, flatpak, upx, …).
The stages share the same Step 1 / Step 2 / Step 3 shape:
- Step 1 (serial,
&mut ctx): render templates, stage files, collect aVec<Job>of fully-owned work units. - Step 2 (parallel, bounded by
ctx.options.parallelism): run one subprocess per job instd::thread::scope. - Step 3 (serial,
&mut ctx): register the returned artifacts.
Before this helper every stage hand-rolled the Step 2 loop —
for chunk in jobs.chunks(n) { thread::scope(|s| …) } with its own
join-unwrap-or-panic handling. The pattern is now shared here so new
parallelized stages just write run_job.
Semantics match the previous hand-rolled loops exactly:
- Bounded concurrency: at most
parallelismworkers run at once, enforced by chunking the job list and scoping threads per-chunk. - Fail-fast within a chunk: if any worker in a chunk fails, the whole chunk still runs to completion (threads are already spawned), but the caller receives the first error and processes no further chunks.
- Panic-safe: a worker panic becomes an
anyhow::Errorannotated withstage_name, so a panicked thread doesn’t leave the pool deadlocked or drop all other results on the floor. - Order-preserving: results are collected in job-submission order, so downstream artifact registration remains deterministic.
Functions§
- join_
panic_ to_ err - Translate a
thread::JoinHandle::joinresult’s panic payload into ananyhow::Errortagged withlabel. The two common panic payload shapes (&'static str/String) are downcast so the surfaced message is readable rather than the opaqueAnyplaceholder. - lock_
recover - Acquire a
Mutexguard, recovering from poison rather than panicking. - run_
parallel_ chunks - Run
run_jobacrossjobswith bounded parallelism. Returns the per-job results in submission order.