From 967344cd29348f2c8aed29c4222d6f813d271dcd Mon Sep 17 00:00:00 2001 From: Technici4n <13494793+Technici4n@users.noreply.github.com> Date: Thu, 2 May 2024 21:55:26 +0200 Subject: [PATCH] Always use CF.allOf --- .../java/net/neoforged/fml/ModLoader.java | 43 +++++++++---------- 1 file changed, 21 insertions(+), 22 deletions(-) diff --git a/loader/src/main/java/net/neoforged/fml/ModLoader.java b/loader/src/main/java/net/neoforged/fml/ModLoader.java index 3fe8f9a15..0b04df0fc 100644 --- a/loader/src/main/java/net/neoforged/fml/ModLoader.java +++ b/loader/src/main/java/net/neoforged/fml/ModLoader.java @@ -207,7 +207,7 @@ public static void dispatchParallelTask(String name, Executor parallelExecutor, Map> modFutures = new IdentityHashMap<>(); var futureList = modList.getSortedMods().stream() .map(modContainer -> { - // Build future for all dependencies first + // Collect futures for all dependencies first var deps = LoadingModList.get().getDependencies(modContainer.getModInfo()); @SuppressWarnings("unchecked") CompletableFuture[] depFutures = new CompletableFuture[deps.size()]; @@ -219,28 +219,27 @@ public static void dispatchParallelTask(String name, Executor parallelExecutor, } } - var combinedFuture = depFutures.length == 0 ? CompletableFuture.completedFuture(null) : CompletableFuture.allOf(depFutures); - // Build the future for this container - var future = combinedFuture.handleAsync((void_, exception) -> { - if (exception != null) { - // If there was any exception, short circuit. - // The exception will already be handled by `waitForFuture` since it comes from another mod. - LOGGER.error("Skipping {} future for mod {} because a dependency threw an exception.", name, modContainer.getModId()); - progress.increment(); - // Throw a marker exception to make sure that dependencies of *this* task don't get executed. - throw new DependentFutureFailedException(); - } - - try { - ModLoadingContext.get().setActiveContainer(modContainer); - task.accept(modContainer); - } finally { - progress.increment(); - ModLoadingContext.get().setActiveContainer(null); - } - return null; - }, parallelExecutor); + var future = CompletableFuture.allOf(depFutures) + .handleAsync((void_, exception) -> { + if (exception != null) { + // If there was any exception, short circuit. + // The exception will already be handled by `waitForFuture` since it comes from another mod. + LOGGER.error("Skipping {} future for mod {} because a dependency threw an exception.", name, modContainer.getModId()); + progress.increment(); + // Throw a marker exception to make sure that dependencies of *this* task don't get executed. + throw new DependentFutureFailedException(); + } + + try { + ModLoadingContext.get().setActiveContainer(modContainer); + task.accept(modContainer); + } finally { + progress.increment(); + ModLoadingContext.get().setActiveContainer(null); + } + return null; + }, parallelExecutor); modFutures.put(modContainer.getModInfo(), future); return future; })