diff --git a/subprojects/parseq/src/main/java/com/linkedin/parseq/promise/Promise.java b/subprojects/parseq/src/main/java/com/linkedin/parseq/promise/Promise.java index 3f01907f..8166ba8d 100644 --- a/subprojects/parseq/src/main/java/com/linkedin/parseq/promise/Promise.java +++ b/subprojects/parseq/src/main/java/com/linkedin/parseq/promise/Promise.java @@ -136,15 +136,20 @@ public interface Promise

{ * @return CompletionStage */ default CompletionStage

toCompletionStage() { - final CompletableFuture

future = new CompletableFuture<>(); - addListener(p -> { - if (!p.isFailed()) { - future.complete(p.get()); + final CompletableFuture

future = new CompletableFuture<>(); + if (isDone()) { + future.complete(get()); + } else if (isFailed()) { + future.completeExceptionally(getError()); + } else { + addListener(p -> { + if (!p.isFailed()) { + future.complete(p.get()); + } else { + future.completeExceptionally(p.getError()); + } + }); } - else { - future.completeExceptionally(p.getError()); - } - }); - return future; + return future; } }