added javadocs for DONE, READY_TRUE, and READY_FALSE ; used it in some places instead of CompletableFuture.completedFuture

This commit is contained in:
Alec Grieser 2017-12-14 10:10:11 -08:00
parent 9934b2e09a
commit 9b1bcea525
3 changed files with 21 additions and 5 deletions

View File

@ -156,7 +156,7 @@ public class LocalityUtil {
CompletableFuture<Boolean> restartGet() {
if(ByteArrayUtil.compareUnsigned(begin, end) >= 0) {
return CompletableFuture.completedFuture(false);
return AsyncUtil.READY_FALSE;
}
lastBegin = begin;
tr.options().setReadSystemKeys();

View File

@ -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<Void> DONE = CompletableFuture.completedFuture(null);
public static final CompletableFuture<Boolean> READY_TRUE = CompletableFuture.completedFuture(true);
public static final CompletableFuture<Boolean> 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<Boolean> 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<Boolean> READY_FALSE = CompletableFuture.completedFuture(Boolean.FALSE);
/**
* Run {@code Function} {@code func}, returning all caught exceptions as a

View File

@ -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;