From b5b6e38cb7a64049c3170ff3fd70a507898f4877 Mon Sep 17 00:00:00 2001 From: Jason Penilla <11360596+jpenilla@users.noreply.github.com> Date: Tue, 22 Oct 2024 13:09:21 -0700 Subject: [PATCH] attempt to execute task on #get to minimize blocking --- .../render/SectionOcclusionGraphMixin.java | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/main/java/ca/spottedleaf/moonrise/mixin/render/SectionOcclusionGraphMixin.java b/src/main/java/ca/spottedleaf/moonrise/mixin/render/SectionOcclusionGraphMixin.java index 433fadb..9cada0b 100644 --- a/src/main/java/ca/spottedleaf/moonrise/mixin/render/SectionOcclusionGraphMixin.java +++ b/src/main/java/ca/spottedleaf/moonrise/mixin/render/SectionOcclusionGraphMixin.java @@ -1,9 +1,11 @@ package ca.spottedleaf.moonrise.mixin.render; +import ca.spottedleaf.concurrentutil.executor.PrioritisedExecutor; import ca.spottedleaf.concurrentutil.executor.thread.PrioritisedThreadPool; import ca.spottedleaf.concurrentutil.util.Priority; import ca.spottedleaf.moonrise.common.util.MoonriseCommon; import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; import java.util.concurrent.Executor; import net.minecraft.client.renderer.SectionOcclusionGraph; import org.spongepowered.asm.mixin.Mixin; @@ -33,11 +35,22 @@ abstract class SectionOcclusionGraphMixin { ) ) private CompletableFuture changeExecutor(final Runnable runnable, final Executor executor) { - return CompletableFuture.runAsync( - runnable, - (final Runnable task) -> { - SECTION_OCCLUSION_EXECUTOR.queueTask(task, Priority.NORMAL); + final PrioritisedExecutor.PrioritisedTask[] prioritisedTask = new PrioritisedExecutor.PrioritisedTask[1]; + final CompletableFuture future = new CompletableFuture<>() { + @Override + public Void get() throws InterruptedException, ExecutionException { + prioritisedTask[0].execute(); + return super.get(); } - ); + }; + prioritisedTask[0] = SECTION_OCCLUSION_EXECUTOR.queueTask(() -> { + try { + runnable.run(); + future.complete(null); + } catch (final Throwable throwable) { + future.completeExceptionally(throwable); + } + }, Priority.NORMAL); + return future; } }