MCPcopy Create free account
hub / github.com/VolmitSoftware/Adapt / execute

Method execute

src/main/java/com/volmit/adapt/util/Chunker.java:47–69  ·  view source on GitHub ↗
(Consumer<T> consumer, Callback<Double> progress, int progressInterval)

Source from the content-addressed store, hash-verified

45 }
46
47 public void execute(Consumer<T> consumer, Callback<Double> progress, int progressInterval) {
48 ChronoLatch cl = new ChronoLatch(progressInterval);
49 Contained<Integer> consumed = new Contained<Integer>(0);
50 executor = Executors.newFixedThreadPool(threads);
51 int length = q.size();
52 int remaining = length;
53
54 while (remaining > 0) {
55 int at = remaining;
56 remaining -= (remaining > workload ? workload : remaining);
57 int to = remaining;
58
59 executor.submit(() ->
60 {
61 J.dofor(at, (i) -> i >= to, -1, (i) -> J.attempt(() -> consumer.accept(q.get(i))));
62 consumed.mod((c) -> c += workload);
63 J.doif(() -> progress != null && cl.flip(), () -> progress.run((double) consumed.get() / (double) length));
64 });
65 }
66
67 executor.shutdown();
68 J.attempt(() -> executor.awaitTermination(100, TimeUnit.HOURS));
69 }
70}

Callers 3

queueMethod · 0.45
lazyMethod · 0.45
submitDataMethod · 0.45

Calls 11

doforMethod · 0.95
attemptMethod · 0.95
modMethod · 0.95
doifMethod · 0.95
flipMethod · 0.95
getMethod · 0.95
shutdownMethod · 0.80
sizeMethod · 0.65
acceptMethod · 0.65
getMethod · 0.65
runMethod · 0.65

Tested by

no test coverage detected