static void parallelDo(Cl l, O... _) { parallelDo(iterator(l), l(l), _); } static void parallelDo(Iterator it, int count, O... _) ctex { optPar int queueSize = 500; optPar int poolSize = coresToUse_fixed(); NotifyingBlockingThreadPoolExecutor e = new(poolSize, queueSize, 15, TimeUnit.SECONDS); // TODO: if poolSize == 1, do it in this thread new Var error; try { 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!); }