2530 |
|
* exceptionally with a CompletionException with this exception as |
2531 |
|
* cause. |
2532 |
|
* |
2533 |
+ |
* <p>Unless overridden by a subclass, a new non-minimal |
2534 |
+ |
* CompletableFuture with all methods available can be obtained from |
2535 |
+ |
* a minimal CompletionStage via {@link #toCompletableFuture()}. |
2536 |
+ |
* For example, completion of a minimal stage can be awaited by |
2537 |
+ |
* |
2538 |
+ |
* <pre> {@code minimalStage.toCompletableFuture().join(); }</pre> |
2539 |
+ |
* |
2540 |
|
* @return the new CompletionStage |
2541 |
|
* @since 9 |
2542 |
|
*/ |
2831 |
|
@Override public CompletableFuture<T> completeOnTimeout |
2832 |
|
(T value, long timeout, TimeUnit unit) { |
2833 |
|
throw new UnsupportedOperationException(); } |
2834 |
+ |
@Override public CompletableFuture<T> toCompletableFuture() { |
2835 |
+ |
Object r; |
2836 |
+ |
if ((r = result) != null) |
2837 |
+ |
return new CompletableFuture<T>(encodeRelay(r)); |
2838 |
+ |
else { |
2839 |
+ |
CompletableFuture<T> d = new CompletableFuture<>(); |
2840 |
+ |
unipush(new UniRelay<T,T>(d, this)); |
2841 |
+ |
return d; |
2842 |
+ |
} |
2843 |
+ |
} |
2844 |
|
} |
2845 |
|
|
2846 |
|
// VarHandle mechanics |