static void parallelDo(Cl l) {
parallelDo(iterator(l), l(l));
}
static void parallelDo(Iterator it, int count) ctex {
int poolSize = coresToUse_fixed(), queueSize = 500;
NotifyingBlockingThreadPoolExecutor e = new(poolSize, queueSize, 15, TimeUnit.SECONDS);
// TODO: if poolSize == 1, do it in this thread
try {
new Var error;
for (A o : iterable(it)) {
if (o == null) continue;
e.execute(r { pcall {
try {
o.run();
} catch e {
error.set(e);
}
}});
}
e.shutdown();
e.awaitTermination(1, TimeUnit.DAYS);
} finally {
e.shutdown();
}
if (error.has())
throw rethrow(error!);
}