diff --git a/bindings/java/src-completable/main/com/apple/foundationdb/LocalityUtil.java b/bindings/java/src-completable/main/com/apple/foundationdb/LocalityUtil.java index 9e4ae395bc..9a2797f1c5 100644 --- a/bindings/java/src-completable/main/com/apple/foundationdb/LocalityUtil.java +++ b/bindings/java/src-completable/main/com/apple/foundationdb/LocalityUtil.java @@ -156,7 +156,7 @@ public class LocalityUtil { CompletableFuture restartGet() { if(ByteArrayUtil.compareUnsigned(begin, end) >= 0) { - return CompletableFuture.completedFuture(false); + return AsyncUtil.READY_FALSE; } lastBegin = begin; tr.options().setReadSystemKeys(); diff --git a/bindings/java/src-completable/main/com/apple/foundationdb/async/AsyncUtil.java b/bindings/java/src-completable/main/com/apple/foundationdb/async/AsyncUtil.java index 5a45f614a3..2d5337439b 100644 --- a/bindings/java/src-completable/main/com/apple/foundationdb/async/AsyncUtil.java +++ b/bindings/java/src-completable/main/com/apple/foundationdb/async/AsyncUtil.java @@ -37,9 +37,25 @@ import java.util.function.Supplier; * Provided utilities for using and manipulating {@link CompletableFuture}s. */ public class AsyncUtil { + /** + * A completed future of type {@link Void}. In particular, it is completed to {@code null}, + * but that shouldn't really matter for the {@link Void} type. This can be used instead + * of creating a new future if one wants to signal that some asynchronous task has + * already been completed. + */ public static final CompletableFuture DONE = CompletableFuture.completedFuture(null); - public static final CompletableFuture READY_TRUE = CompletableFuture.completedFuture(true); - public static final CompletableFuture READY_FALSE = CompletableFuture.completedFuture(false); + /** + * A completed future of type {@link Boolean} that is set to {@code true}. This can be + * used instead of creating a new future if one wants to signal that some task has + * already been completed with a {@code true} result. + */ + public static final CompletableFuture READY_TRUE = CompletableFuture.completedFuture(Boolean.TRUE); + /** + * A completed future of type {@link Boolean} that is set to {@code false}. This can be + * used instead of creating a new future if one wants to signal that some task has + * already been completed with a {@code false} result. + */ + public static final CompletableFuture READY_FALSE = CompletableFuture.completedFuture(Boolean.FALSE); /** * Run {@code Function} {@code func}, returning all caught exceptions as a diff --git a/bindings/java/src-completable/main/com/apple/foundationdb/directory/DirectoryLayer.java b/bindings/java/src-completable/main/com/apple/foundationdb/directory/DirectoryLayer.java index 1d7aeba10d..e48a8349e3 100644 --- a/bindings/java/src-completable/main/com/apple/foundationdb/directory/DirectoryLayer.java +++ b/bindings/java/src-completable/main/com/apple/foundationdb/directory/DirectoryLayer.java @@ -907,14 +907,14 @@ public class DirectoryLayer implements Directory { return AsyncUtil.whileTrue(() -> { if(index == path.size()) - return CompletableFuture.completedFuture(false); + return AsyncUtil.READY_FALSE; return tr.get(node.subspace.get(SUB_DIR_KEY).get(path.get(index)).getKey()).thenComposeAsync(key -> { currentPath.add(path.get(index)); node = new Node(nodeWithPrefix(key), currentPath, path); if(!node.exists()) - return CompletableFuture.completedFuture(false); + return AsyncUtil.READY_FALSE; return node.loadMetadata(tr).thenApply(ignore -> { ++index;