1+ package scala .concurrent
2+
3+ import java .util .concurrent .CompletionStage
4+
5+ package object java8 {
6+
7+ implicit class futureToCompletionStage [T ](val f : Future [T ]) extends AnyVal {
8+ /**
9+ * Returns a CompletionStage that will be completed with the same value or
10+ * exception as the given Scala Future when that completes. Since the Future is a read-only
11+ * representation, this CompletionStage does not support the
12+ * <code>toCompletableFuture</code> method. The semantics of Scala Future
13+ * demand that all callbacks are invoked asynchronously by default, therefore
14+ * the returned CompletionStage routes all calls to synchronous
15+ * transformations to their asynchronous counterparts, i.e.
16+ * <code>thenRun</code> will internally call <code>thenRunAsync</code>.
17+ *
18+ * @param f The Scala Future which may eventually supply the completion for
19+ * the returned CompletionStage
20+ * @return a CompletionStage that runs all callbacks asynchronously and does
21+ * not support the CompletableFuture interface
22+ */
23+ def toJava : CompletionStage [T ] = FutureConverter .toJava(f)
24+ }
25+
26+ implicit class completionStageToFuture [T ](val cs : CompletionStage [T ]) extends AnyVal {
27+ /**
28+ * Returns a Scala Future that will be completed with the same value or
29+ * exception as the given CompletionStage when that completes. Transformations
30+ * of the returned Future are executed asynchronously as specified by the
31+ * ExecutionContext that is given to the combinator methods.
32+ *
33+ * @param cs The CompletionStage which may eventually supply the completion
34+ * for the returned Scala Future
35+ * @return a Scala Future that represents the CompletionStage's completion
36+ */
37+ def toScala : Future [T ] = FutureConverter .toScala(cs)
38+ }
39+ }
0 commit comments