File tree Expand file tree Collapse file tree 1 file changed +14
-9
lines changed
subprojects/parseq/src/main/java/com/linkedin/parseq/promise Expand file tree Collapse file tree 1 file changed +14
-9
lines changed Original file line number Diff line number Diff line change @@ -136,15 +136,20 @@ public interface Promise<P> {
136136 * @return CompletionStage
137137 */
138138 default CompletionStage <P > toCompletionStage () {
139- final CompletableFuture <P > future = new CompletableFuture <>();
140- addListener (p -> {
141- if (!p .isFailed ()) {
142- future .complete (p .get ());
139+ final CompletableFuture <P > future = new CompletableFuture <>();
140+ if (isDone ()) {
141+ future .complete (get ());
142+ } else if (isFailed ()) {
143+ future .completeExceptionally (getError ());
144+ } else {
145+ addListener (p -> {
146+ if (!p .isFailed ()) {
147+ future .complete (p .get ());
148+ } else {
149+ future .completeExceptionally (p .getError ());
150+ }
151+ });
143152 }
144- else {
145- future .completeExceptionally (p .getError ());
146- }
147- });
148- return future ;
153+ return future ;
149154 }
150155}
You can’t perform that action at this time.
0 commit comments