ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/main/java/util/concurrent/CompletionStage.java
Revision: 1.5
Committed: Sat Jul 6 08:09:21 2013 UTC (10 years, 10 months ago) by jsr166
Branch: MAIN
Changes since 1.4: +1 -1 lines
Log Message:
whitespace

File Contents

# User Rev Content
1 dl 1.1 /*
2     * Written by Doug Lea with assistance from members of JCP JSR-166
3     * Expert Group and released to the public domain, as explained at
4     * http://creativecommons.org/publicdomain/zero/1.0/
5     */
6    
7     package java.util.concurrent;
8     import java.util.function.Supplier;
9     import java.util.function.Consumer;
10     import java.util.function.BiConsumer;
11     import java.util.function.Function;
12     import java.util.function.BiFunction;
13     import java.util.concurrent.Executor;
14    
15     /**
16     * A stage of a possibly asynchronous computation, that performs an
17     * action or computes a value when another CompletionStage completes.
18     * A stage completes upon termination of its computation, but this may
19     * in turn trigger other dependent stages. The functionality defined
20     * in this interface takes only a few basic forms, which expand out to
21     * a larger set of methods to capture a range of usage styles: <ul>
22     *
23     * <li>The computation performed by a stage may be expressed as a
24     * Function, Consumer, or Runnable (using methods with names including
25     * <em>apply</em>, <em>accept</em>, or <em>run</em>, respectively)
26 dl 1.2 * depending on whether it requires arguments and/or produces results.
27 dl 1.1 * For example, {@code stage.thenApply(x -> square(x)).thenAccept(x ->
28     * System.out.print(x)).thenRun(() -> System.out.println())}. An
29     * additional form (<em>compose</em>) applies functions of stages
30 dl 1.2 * themselves, rather than their results. </li>
31 dl 1.1 *
32     * <li> One stage's execution may be triggered by completion of a
33     * single stage, or both of two stages, or either of two stages.
34     * Dependencies on a single stage are arranged using methods with
35     * prefix <em>then</em>. Those triggered by completion of
36     * <em>both</em> of two stages may <em>combine</em> their results or
37     * effects, using correspondingly named methods. Those triggered by
38     * <em>either</em> of two stages make no guarantees about which of the
39     * results or effects are used for the dependent stage's
40     * computation.</li>
41     *
42     * <li> Dependencies among stages control the triggering of
43     * computations, but do not otherwise guarantee any particular
44     * ordering. Additionally, execution of a new stage's computations may
45     * be arranged in any of three ways: default execution, default
46     * asynchronous execution (using methods with suffix <em>async</em>
47     * that employ the stage's default asynchronous execution facility),
48 dl 1.2 * or custom (via a supplied {@link Executor}). The execution
49 dl 1.1 * properties of default and async modes are specified by
50     * CompletionStage implementations, not this interface. Methods with
51     * explicit Executor arguments may have arbitrary execution
52     * properties, and might not even support concurrent execution, but
53     * are arranged for processing in a way that accommodates asynchrony.
54     *
55     * <li> Two method forms support processing whether the triggering
56     * stage completed normally or exceptionally: Method {@link
57     * #whenComplete whenComplete} allows injection of an action
58     * regardless of outcome, otherwise preserving the outcome in its
59     * completion. Method {@link #handle handle} additionally allows the
60     * stage to compute a replacement result that may enable further
61     * processing by other dependent stages. In all other cases, if a
62     * stage's computation terminates abruptly with an (unchecked)
63     * exception or error, then all dependent stages requiring its
64     * completion complete exceptionally as well, with a {@link
65     * CompletionException} holding the exception as its cause. If a
66     * stage is dependent on <em>both</em> of two stages, and both
67     * complete exceptionally, then the CompletionException may correspond
68     * to either one of these exceptions. If a stage is dependent on
69     * <em>either</em> of two others, and only one of them completes
70     * exceptionally, no guarantees are made about whether the dependent
71     * stage completes normally or exceptionally. In the case of method
72 dl 1.2 * {@code whenComplete}, when the supplied action itself encounters an
73 dl 1.1 * exception, then the stage exceptionally completes with this
74     * exception if not already completed exceptionally.</li>
75     *
76     * </ul>
77     *
78     * <p>All methods adhere to the above triggering, execution, and
79     * exceptional completion specifications (which are not repeated in
80     * individual method specifications). Additionally, while arguments
81     * used to pass a completion result (that is, for parameters of type
82     * {@code T}) for methods accepting them may be null, passing a null
83     * value for any other parameter will result in a {@link
84     * NullPointerException} being thrown.
85     *
86 jsr166 1.3 * <p>This interface does not define methods for initially creating,
87 dl 1.1 * forcibly completing normally or exceptionally, probing completion
88     * status or results, or awaiting completion of a stage.
89     * Implementations of CompletionStage may provide means of achieving
90     * such effects, as appropriate. Method {@link #toCompletableFuture}
91     * enables interoperability among different implementations of this
92     * interface by providing a common conversion type.
93     *
94     * @author Doug Lea
95     * @since 1.8
96     */
97     public interface CompletionStage<T> {
98    
99     /**
100     * Returns a new CompletionStage that, when this stage completes
101     * normally, is executed with this stage's result as the argument
102     * to the supplied function.
103     *
104     * See the {@link CompletionStage} documentation for rules
105     * covering exceptional completion.
106     *
107     * @param fn the function to use to compute the value of
108     * the returned CompletionStage
109     * @return the new CompletionStage
110     */
111     public <U> CompletionStage<U> thenApply(Function<? super T,? extends U> fn);
112    
113     /**
114     * Returns a new CompletionStage that, when this stage completes
115     * normally, is executed using this stage's default asynchronous
116     * execution facility, with this stage's result as the argument to
117     * the supplied function.
118     *
119     * See the {@link CompletionStage} documentation for rules
120     * covering exceptional completion.
121     *
122     * @param fn the function to use to compute the value of
123     * the returned CompletionStage
124     * @return the new CompletionStage
125     */
126     public <U> CompletionStage<U> thenApplyAsync
127     (Function<? super T,? extends U> fn);
128    
129     /**
130     * Returns a new CompletionStage that, when this stage completes
131     * normally, is executed using the supplied Executor, with this
132     * stage's result as the argument to the supplied function.
133     *
134     * See the {@link CompletionStage} documentation for rules
135     * covering exceptional completion.
136     *
137     * @param fn the function to use to compute the value of
138     * the returned CompletionStage
139     * @param executor the executor to use for asynchronous execution
140     * @return the new CompletionStage
141     */
142     public <U> CompletionStage<U> thenApplyAsync
143     (Function<? super T,? extends U> fn,
144     Executor executor);
145    
146     /**
147     * Returns a new CompletionStage that, when this stage completes
148     * normally, is executed with this stage's result as the argument
149     * to the supplied action.
150     *
151     * See the {@link CompletionStage} documentation for rules
152     * covering exceptional completion.
153     *
154     * @param action the action to perform before completing the
155     * returned CompletionStage
156     * @return the new CompletionStage
157     */
158     public CompletionStage<Void> thenAccept(Consumer<? super T> action);
159    
160     /**
161     * Returns a new CompletionStage that, when this stage completes
162     * normally, is executed using this stage's default asynchronous
163     * execution facility, with this stage's result as the argument to
164     * the supplied action.
165     *
166     * See the {@link CompletionStage} documentation for rules
167     * covering exceptional completion.
168     *
169     * @param action the action to perform before completing the
170     * returned CompletionStage
171     * @return the new CompletionStage
172     */
173     public CompletionStage<Void> thenAcceptAsync(Consumer<? super T> action);
174    
175     /**
176     * Returns a new CompletionStage that, when this stage completes
177     * normally, is executed using the supplied Executor, with this
178     * stage's result as the argument to the supplied action.
179     *
180     * See the {@link CompletionStage} documentation for rules
181     * covering exceptional completion.
182     *
183     * @param action the action to perform before completing the
184     * returned CompletionStage
185     * @param executor the executor to use for asynchronous execution
186     * @return the new CompletionStage
187     */
188     public CompletionStage<Void> thenAcceptAsync(Consumer<? super T> action,
189 jsr166 1.5 Executor executor);
190 dl 1.1 /**
191     * Returns a new CompletionStage that, when this stage completes
192     * normally, executes the given action.
193     *
194     * See the {@link CompletionStage} documentation for rules
195     * covering exceptional completion.
196     *
197     * @param action the action to perform before completing the
198     * returned CompletionStage
199     * @return the new CompletionStage
200     */
201     public CompletionStage<Void> thenRun(Runnable action);
202    
203     /**
204     * Returns a new CompletionStage that, when this stage completes
205     * normally, executes the given action using this stage's default
206     * asynchronous execution facility.
207     *
208     * See the {@link CompletionStage} documentation for rules
209     * covering exceptional completion.
210     *
211     * @param action the action to perform before completing the
212     * returned CompletionStage
213     * @return the new CompletionStage
214     */
215     public CompletionStage<Void> thenRunAsync(Runnable action);
216    
217     /**
218     * Returns a new CompletionStage that, when this stage completes
219     * normally, executes the given action using the supplied Executor.
220     *
221     * See the {@link CompletionStage} documentation for rules
222     * covering exceptional completion.
223     *
224     * @param action the action to perform before completing the
225     * returned CompletionStage
226     * @param executor the executor to use for asynchronous execution
227     * @return the new CompletionStage
228     */
229     public CompletionStage<Void> thenRunAsync(Runnable action,
230     Executor executor);
231    
232     /**
233     * Returns a new CompletionStage that, when this and the other
234     * given stage both complete normally, is executed with the two
235     * results as arguments to the supplied function.
236     *
237     * See the {@link CompletionStage} documentation for rules
238     * covering exceptional completion.
239     *
240     * @param other the other CompletionStage
241     * @param fn the function to use to compute the value of
242     * the returned CompletionStage
243     * @return the new CompletionStage
244     */
245     public <U,V> CompletionStage<V> thenCombine
246     (CompletionStage<? extends U> other,
247     BiFunction<? super T,? super U,? extends V> fn);
248    
249     /**
250     * Returns a new CompletionStage that, when this and the other
251     * given stage complete normally, is executed using this stage's
252     * default asynchronous execution facility, with the two results
253     * as arguments to the supplied function.
254     *
255     * See the {@link CompletionStage} documentation for rules
256     * covering exceptional completion.
257     *
258     * @param other the other CompletionStage
259     * @param fn the function to use to compute the value of
260     * the returned CompletionStage
261     * @return the new CompletionStage
262     */
263     public <U,V> CompletionStage<V> thenCombineAsync
264     (CompletionStage<? extends U> other,
265     BiFunction<? super T,? super U,? extends V> fn);
266    
267     /**
268     * Returns a new CompletionStage that, when this and the other
269     * given stage complete normally, is executed using the supplied
270     * executor, with the two results as arguments to the supplied
271     * function.
272     *
273     * See the {@link CompletionStage} documentation for rules
274     * covering exceptional completion.
275     *
276     * @param other the other CompletionStage
277     * @param fn the function to use to compute the value of
278     * the returned CompletionStage
279     * @param executor the executor to use for asynchronous execution
280     * @return the new CompletionStage
281     */
282     public <U,V> CompletionStage<V> thenCombineAsync
283     (CompletionStage<? extends U> other,
284     BiFunction<? super T,? super U,? extends V> fn,
285     Executor executor);
286    
287     /**
288     * Returns a new CompletionStage that, when this and the other
289     * given stage both complete normally, is executed with the two
290     * results as arguments to the supplied action.
291     *
292     * See the {@link CompletionStage} documentation for rules
293     * covering exceptional completion.
294     *
295     * @param other the other CompletionStage
296     * @param action the action to perform before completing the
297     * returned CompletionStage
298     * @return the new CompletionStage
299     */
300     public <U> CompletionStage<Void> thenAcceptBoth
301     (CompletionStage<? extends U> other,
302     BiConsumer<? super T, ? super U> action);
303    
304     /**
305     * Returns a new CompletionStage that, when this and the other
306     * given stage complete normally, is executed using this stage's
307     * default asynchronous execution facility, with the two results
308     * as arguments to the supplied action.
309     *
310     * @param other the other CompletionStage
311     * @param action the action to perform before completing the
312     * returned CompletionStage
313     * @return the new CompletionStage
314     */
315     public <U> CompletionStage<Void> thenAcceptBothAsync
316     (CompletionStage<? extends U> other,
317     BiConsumer<? super T, ? super U> action);
318    
319     /**
320     * Returns a new CompletionStage that, when this and the other
321     * given stage complete normally, is executed using the supplied
322     * executor, with the two results as arguments to the supplied
323     * function.
324     *
325     * @param other the other CompletionStage
326     * @param action the action to perform before completing the
327     * returned CompletionStage
328     * @param executor the executor to use for asynchronous execution
329     * @return the new CompletionStage
330     */
331     public <U> CompletionStage<Void> thenAcceptBothAsync
332     (CompletionStage<? extends U> other,
333     BiConsumer<? super T, ? super U> action,
334     Executor executor);
335    
336     /**
337     * Returns a new CompletionStage that, when this and the other
338     * given stage both complete normally, executes the given action.
339     *
340     * See the {@link CompletionStage} documentation for rules
341     * covering exceptional completion.
342     *
343     * @param other the other CompletionStage
344     * @param action the action to perform before completing the
345     * returned CompletionStage
346     * @return the new CompletionStage
347     */
348     public CompletionStage<Void> runAfterBoth(CompletionStage<?> other,
349     Runnable action);
350     /**
351     * Returns a new CompletionStage that, when this and the other
352     * given stage complete normally, executes the given action using
353     * this stage's default asynchronous execution facility.
354     *
355     * See the {@link CompletionStage} documentation for rules
356     * covering exceptional completion.
357     *
358     * @param other the other CompletionStage
359     * @param action the action to perform before completing the
360     * returned CompletionStage
361     * @return the new CompletionStage
362     */
363     public CompletionStage<Void> runAfterBothAsync(CompletionStage<?> other,
364     Runnable action);
365    
366     /**
367     * Returns a new CompletionStage that, when this and the other
368     * given stage complete normally, executes the given action using
369     * the supplied executor
370     *
371     * See the {@link CompletionStage} documentation for rules
372     * covering exceptional completion.
373     *
374     * @param other the other CompletionStage
375     * @param action the action to perform before completing the
376     * returned CompletionStage
377     * @param executor the executor to use for asynchronous execution
378     * @return the new CompletionStage
379     */
380     public CompletionStage<Void> runAfterBothAsync(CompletionStage<?> other,
381     Runnable action,
382     Executor executor);
383     /**
384     * Returns a new CompletionStage that, when either this or the
385     * other given stage complete normally, is executed with the
386     * corresponding result as argument to the supplied function.
387     *
388     * See the {@link CompletionStage} documentation for rules
389     * covering exceptional completion.
390     *
391     * @param other the other CompletionStage
392     * @param fn the function to use to compute the value of
393     * the returned CompletionStage
394     * @return the new CompletionStage
395     */
396     public <U> CompletionStage<U> applyToEither
397     (CompletionStage<? extends T> other,
398     Function<? super T, U> fn);
399    
400     /**
401     * Returns a new CompletionStage that, when either this or the
402     * other given stage complete normally, is executed using this
403     * stage's default asynchronous execution facility, with the
404     * corresponding result as argument to the supplied function.
405     *
406     * See the {@link CompletionStage} documentation for rules
407     * covering exceptional completion.
408     *
409     * @param other the other CompletionStage
410     * @param fn the function to use to compute the value of
411     * the returned CompletionStage
412     * @return the new CompletionStage
413     */
414     public <U> CompletionStage<U> applyToEitherAsync
415     (CompletionStage<? extends T> other,
416     Function<? super T, U> fn);
417    
418     /**
419     * Returns a new CompletionStage that, when either this or the
420     * other given stage complete normally, is executed using the
421     * supplied executor, with the corresponding result as argument to
422     * the supplied function.
423     *
424     * See the {@link CompletionStage} documentation for rules
425     * covering exceptional completion.
426     *
427     * @param other the other CompletionStage
428     * @param fn the function to use to compute the value of
429     * the returned CompletionStage
430     * @param executor the executor to use for asynchronous execution
431     * @return the new CompletionStage
432     */
433     public <U> CompletionStage<U> applyToEitherAsync
434     (CompletionStage<? extends T> other,
435     Function<? super T, U> fn,
436     Executor executor);
437    
438     /**
439     * Returns a new CompletionStage that, when either this or the
440     * other given stage complete normally, is executed with the
441     * corresponding result as argument to the supplied action.
442     *
443     * See the {@link CompletionStage} documentation for rules
444     * covering exceptional completion.
445     *
446     * @param other the other CompletionStage
447     * @param action the action to perform before completing the
448     * returned CompletionStage
449     * @return the new CompletionStage
450     */
451     public CompletionStage<Void> acceptEither
452     (CompletionStage<? extends T> other,
453     Consumer<? super T> action);
454    
455     /**
456     * Returns a new CompletionStage that, when either this or the
457     * other given stage complete normally, is executed using this
458     * stage's default asynchronous execution facility, with the
459     * corresponding result as argument to the supplied action.
460     *
461     * See the {@link CompletionStage} documentation for rules
462     * covering exceptional completion.
463     *
464     * @param other the other CompletionStage
465     * @param action the action to perform before completing the
466     * returned CompletionStage
467     * @return the new CompletionStage
468     */
469     public CompletionStage<Void> acceptEitherAsync
470     (CompletionStage<? extends T> other,
471     Consumer<? super T> action);
472    
473     /**
474     * Returns a new CompletionStage that, when either this or the
475     * other given stage complete normally, is executed using the
476     * supplied executor, with the corresponding result as argument to
477     * the supplied function.
478     *
479     * See the {@link CompletionStage} documentation for rules
480     * covering exceptional completion.
481     *
482     * @param other the other CompletionStage
483     * @param action the action to perform before completing the
484     * returned CompletionStage
485     * @param executor the executor to use for asynchronous execution
486     * @return the new CompletionStage
487     */
488     public CompletionStage<Void> acceptEitherAsync
489     (CompletionStage<? extends T> other,
490     Consumer<? super T> action,
491     Executor executor);
492    
493     /**
494     * Returns a new CompletionStage that, when either this or the
495     * other given stage complete normally, executes the given action.
496     *
497     * See the {@link CompletionStage} documentation for rules
498     * covering exceptional completion.
499     *
500     * @param other the other CompletionStage
501     * @param action the action to perform before completing the
502     * returned CompletionStage
503     * @return the new CompletionStage
504     */
505     public CompletionStage<Void> runAfterEither(CompletionStage<?> other,
506     Runnable action);
507     /**
508     * Returns a new CompletionStage that, when either this or the
509     * other given stage complete normally, executes the given action
510     * using this stage's default asynchronous execution facility.
511     *
512     * See the {@link CompletionStage} documentation for rules
513     * covering exceptional completion.
514     *
515     * @param other the other CompletionStage
516     * @param action the action to perform before completing the
517     * returned CompletionStage
518     * @return the new CompletionStage
519     */
520     public CompletionStage<Void> runAfterEitherAsync
521     (CompletionStage<?> other,
522     Runnable action);
523    
524     /**
525     * Returns a new CompletionStage that, when either this or the
526     * other given stage complete normally, executes the given action
527     * using supplied executor.
528     *
529     * See the {@link CompletionStage} documentation for rules
530     * covering exceptional completion.
531     *
532     * @param other the other CompletionStage
533     * @param action the action to perform before completing the
534     * returned CompletionStage
535     * @param executor the executor to use for asynchronous execution
536     * @return the new CompletionStage
537     */
538     public CompletionStage<Void> runAfterEitherAsync
539     (CompletionStage<?> other,
540     Runnable action,
541     Executor executor);
542    
543     /**
544     * Returns a new CompletionStage that, when this stage completes
545     * normally, is executed with this stage as the argument
546     * to the supplied function.
547     *
548     * See the {@link CompletionStage} documentation for rules
549     * covering exceptional completion.
550     *
551     * @param fn the function returning a new CompletionStage
552     * @return the CompletionStage
553     */
554     public <U> CompletionStage<U> thenCompose
555     (Function<? super T, ? extends CompletionStage<U>> fn);
556    
557     /**
558     * Returns a new CompletionStage that, when this stage completes
559     * normally, is executed using this stage's default asynchronous
560     * execution facility, with this stage as the argument to the
561     * supplied function.
562     *
563     * See the {@link CompletionStage} documentation for rules
564     * covering exceptional completion.
565     *
566     * @param fn the function returning a new CompletionStage
567     * @return the CompletionStage
568     */
569     public <U> CompletionStage<U> thenComposeAsync
570     (Function<? super T, ? extends CompletionStage<U>> fn);
571    
572     /**
573     * Returns a new CompletionStage that, when this stage completes
574     * normally, is executed using the supplied Executor, with this
575     * stage's result as the argument to the supplied function.
576     *
577     * See the {@link CompletionStage} documentation for rules
578     * covering exceptional completion.
579     *
580     * @param fn the function returning a new CompletionStage
581     * @param executor the executor to use for asynchronous execution
582     * @return the CompletionStage
583     */
584     public <U> CompletionStage<U> thenComposeAsync
585     (Function<? super T, ? extends CompletionStage<U>> fn,
586     Executor executor);
587    
588     /**
589     * Returns a new CompletionStage that, when this stage completes
590     * exceptionally, is executed with this stage's exception as the
591     * argument to the supplied function. Otherwise, if this stage
592     * completes normally, then the returned stage also completes
593     * normally with the same value.
594     *
595     * @param fn the function to use to compute the value of the
596     * returned CompletionStage if this CompletionStage completed
597     * exceptionally
598     * @return the new CompletionStage
599     */
600     public CompletionStage<T> exceptionally
601     (Function<Throwable, ? extends T> fn);
602    
603     /**
604     * Returns a new CompletionStage with the same result or exception
605     * as this stage, and when this stage completes, executes the
606     * given action with the result (or {@code null} if none) and the
607     * exception (or {@code null} if none) of this stage.
608     *
609     * @param action the action to perform
610     */
611     public CompletionStage<T> whenComplete
612     (BiConsumer<? super T, ? super Throwable> action);
613    
614     /**
615     * Returns a new CompletionStage with the same result or exception
616     * as this stage, and when this stage completes, executes the
617     * given action executes the given action using this stage's
618     * default asynchronous execution facility, with the result (or
619     * {@code null} if none) and the exception (or {@code null} if
620     * none) of this stage as arguments.
621     *
622     * @param action the action to perform
623     */
624     public CompletionStage<T> whenCompleteAsync
625     (BiConsumer<? super T, ? super Throwable> action);
626    
627     /**
628     * Returns a new CompletionStage with the same result or exception
629     * as this stage, and when this stage completes, executes using
630     * the supplied Executor, the given action with the result (or
631     * {@code null} if none) and the exception (or {@code null} if
632     * none) of this stage as arguments.
633     *
634     * @param action the action to perform
635     */
636     public CompletionStage<T> whenCompleteAsync
637     (BiConsumer<? super T, ? super Throwable> action,
638     Executor executor);
639    
640     /**
641     * Returns a new CompletionStage that, when this stage completes
642     * either normally or exceptionally, is executed with this stage's
643     * result and exception as arguments to the supplied function.
644     * The given function is invoked with the result (or {@code null}
645     * if none) and the exception (or {@code null} if none) of this
646     * stage when complete as arguments.
647     *
648     * @param fn the function to use to compute the value of the
649     * returned CompletionStage
650     * @return the new CompletionStage
651     */
652     public <U> CompletionStage<U> handle
653     (BiFunction<? super T, Throwable, ? extends U> fn);
654    
655     /**
656     * Returns a new CompletionStage that, when this stage completes
657     * either normally or exceptionally, is executed using this stage's
658     * default asynchronous execution facility, with this stage's
659     * result and exception as arguments to the supplied function.
660     * The given function is invoked with the result (or {@code null}
661     * if none) and the exception (or {@code null} if none) of this
662     * stage when complete as arguments.
663     *
664     * @param fn the function to use to compute the value of the
665     * returned CompletionStage
666     * @return the new CompletionStage
667     */
668     public <U> CompletionStage<U> handleAsync
669     (BiFunction<? super T, Throwable, ? extends U> fn);
670    
671     /**
672     * Returns a new CompletionStage that, when this stage completes
673     * either normally or exceptionally, is executed using the
674     * supplied executor, with this stage's result and exception as
675     * arguments to the supplied function. The given function is
676     * invoked with the result (or {@code null} if none) and the
677     * exception (or {@code null} if none) of this stage when complete
678     * as arguments.
679     *
680     * @param fn the function to use to compute the value of the
681     * returned CompletionStage
682     * @return the new CompletionStage
683     */
684     public <U> CompletionStage<U> handleAsync
685     (BiFunction<? super T, Throwable, ? extends U> fn,
686     Executor executor);
687    
688     /**
689     * Returns a {@link CompletableFuture} maintaining the same
690     * completion properties as this stage. If this stage is already a
691     * CompletableFuture, this method may return this stage itself.
692     * Otherwise, invocation of this method may be equivalent in
693     * effect to {@code thenApply(x -> x)}, but returning an instance
694     * of type {@code CompletableFuture}. A CompletionStage
695     * implementation that does not choose to interoperate with others
696 jsr166 1.4 * may throw {@code UnsupportedOperationException}.
697 dl 1.1 *
698     * @return the CompletableFuture
699     */
700     public CompletableFuture<T> toCompletableFuture();
701    
702     }