2545 |
|
* exceptionally with a CompletionException with this exception as |
2546 |
|
* cause. |
2547 |
|
* |
2548 |
+ |
* <p>Unless overridden by a subclass, a new non-minimal |
2549 |
+ |
* CompletableFuture with all methods available can be obtained from |
2550 |
+ |
* a minimal CompletionStage via {@link #toCompletableFuture()}. |
2551 |
+ |
* For example, completion of a minimal stage can be awaited by |
2552 |
+ |
* |
2553 |
+ |
* <pre> {@code minimalStage.toCompletableFuture().join(); }</pre> |
2554 |
+ |
* |
2555 |
|
* @return the new CompletionStage |
2556 |
|
* @since 9 |
2557 |
|
*/ |
2846 |
|
@Override public CompletableFuture<T> completeOnTimeout |
2847 |
|
(T value, long timeout, TimeUnit unit) { |
2848 |
|
throw new UnsupportedOperationException(); } |
2849 |
+ |
@Override public CompletableFuture<T> toCompletableFuture() { |
2850 |
+ |
Object r; |
2851 |
+ |
if ((r = result) != null) |
2852 |
+ |
return new CompletableFuture<T>(encodeRelay(r)); |
2853 |
+ |
else { |
2854 |
+ |
CompletableFuture<T> d = new CompletableFuture<>(); |
2855 |
+ |
unipush(new UniRelay<T,T>(d, this)); |
2856 |
+ |
return d; |
2857 |
+ |
} |
2858 |
+ |
} |
2859 |
|
} |
2860 |
|
|
2861 |
|
// Unsafe mechanics |