diff --git a/src/main/java/com/pivovarit/collectors/Dispatcher.java b/src/main/java/com/pivovarit/collectors/Dispatcher.java index 348b62e2..82a8609b 100644 --- a/src/main/java/com/pivovarit/collectors/Dispatcher.java +++ b/src/main/java/com/pivovarit/collectors/Dispatcher.java @@ -21,10 +21,8 @@ final class Dispatcher { private static final Runnable POISON_PILL = () -> System.out.println("Why so serious?"); private final CompletableFuture completionSignaller = new CompletableFuture<>(); - private final BlockingQueue workingQueue = new LinkedBlockingQueue<>(); - private final ExecutorService dispatcher = Executors.newVirtualThreadPerTaskExecutor(); private final Executor executor; private final Semaphore limiter; @@ -53,7 +51,7 @@ static Dispatcher virtual() { void start() { if (!started.getAndSet(true)) { - dispatcher.execute(() -> { + Thread.ofVirtual().start(() -> { try { while (true) { try { @@ -90,8 +88,6 @@ void stop() { workingQueue.put(POISON_PILL); } catch (InterruptedException e) { completionSignaller.completeExceptionally(e); - } finally { - dispatcher.shutdown(); } } @@ -123,7 +119,6 @@ private FutureTask completionTask(Supplier supplier, InterruptibleCompl private void handle(Throwable e) { shortCircuited = true; completionSignaller.completeExceptionally(e); - dispatcher.shutdownNow(); } private static Function shortcircuit(InterruptibleCompletableFuture future) { diff --git a/src/main/java/com/pivovarit/collectors/FutureCollectors.java b/src/main/java/com/pivovarit/collectors/FutureCollectors.java index afab87b4..2ae218c5 100644 --- a/src/main/java/com/pivovarit/collectors/FutureCollectors.java +++ b/src/main/java/com/pivovarit/collectors/FutureCollectors.java @@ -19,7 +19,7 @@ final class FutureCollectors { .collect(collector)); for (var f : list) { - f.whenComplete((t, throwable) -> { + f.whenComplete((__, throwable) -> { if (throwable != null) { future.completeExceptionally(throwable); }