Skip to content

Commit

Permalink
perf: do not wait for server thread when dispatching tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
ishland committed Feb 24, 2024
1 parent a60f083 commit 1791578
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.function.Function;

public class FabricWorld implements World {
private static final int TICKING_LOAD_DURATION = Input.tryInteger(System.getProperty("chunky.tickingLoadDuration")).orElse(0);
Expand Down Expand Up @@ -59,7 +60,7 @@ public String getKey() {
@Override
public CompletableFuture<Boolean> isChunkGenerated(final int x, final int z) {
if (Thread.currentThread() != serverWorld.getServer().getThread()) {
return CompletableFuture.supplyAsync(() -> isChunkGenerated(x, z), serverWorld.getServer()).join();
return CompletableFuture.supplyAsync(() -> isChunkGenerated(x, z), serverWorld.getServer()).thenCompose(Function.identity());
} else {
final ChunkPos chunkPos = new ChunkPos(x, z);
final ServerChunkManager serverChunkManager = serverWorld.getChunkManager();
Expand Down Expand Up @@ -97,7 +98,7 @@ public CompletableFuture<Boolean> isChunkGenerated(final int x, final int z) {
@Override
public CompletableFuture<Void> getChunkAtAsync(final int x, final int z) {
if (Thread.currentThread() != serverWorld.getServer().getThread()) {
return CompletableFuture.supplyAsync(() -> getChunkAtAsync(x, z), serverWorld.getServer()).join();
return CompletableFuture.supplyAsync(() -> getChunkAtAsync(x, z), serverWorld.getServer()).thenCompose(Function.identity());
} else {
final ChunkPos chunkPos = new ChunkPos(x, z);
final ServerChunkManager serverChunkManager = serverWorld.getChunkManager();
Expand Down

0 comments on commit 1791578

Please sign in to comment.