Skip to content

Commit

Permalink
attempt to execute task on #get to minimize blocking
Browse files Browse the repository at this point in the history
  • Loading branch information
jpenilla committed Oct 22, 2024
1 parent a4da57a commit 93958c7
Showing 1 changed file with 18 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -33,11 +35,22 @@ abstract class SectionOcclusionGraphMixin {
)
)
private CompletableFuture<Void> 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<Void> 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;
}
}

0 comments on commit 93958c7

Please sign in to comment.