@@ -23,7 +23,9 @@ import scala.util.{Failure, Success, Try}
2323
2424// TODO: make this private[scala] when genjavadoc allows for that.
2525object FuturesConvertersImpl {
26- class CF [T ](val wrapped : Future [T ]) extends CompletableFuture [T ] with (Try [T ] => Unit ) {
26+ class CF [T ](val wrapped : Future [T ], executor : Executor ) extends CompletableFuture [T ] with (Try [T ] => Unit ) {
27+ def this (wrapped : Future [T ]) = this (wrapped, ForkJoinPool .commonPool())
28+
2729 override def apply (t : Try [T ]): Unit = t match {
2830 case Success (v) => complete(v)
2931 case Failure (e) => completeExceptionally(e)
@@ -32,29 +34,29 @@ object FuturesConvertersImpl {
3234 /*
3335 * Ensure that completions of this future cannot hold the Scala Future’s completer hostage.
3436 */
35- override def thenApply [U ](fn : JF [_ >: T , _ <: U ]): CompletableFuture [U ] = thenApplyAsync(fn)
37+ override def thenApply [U ](fn : JF [_ >: T , _ <: U ]): CompletableFuture [U ] = thenApplyAsync(fn, executor )
3638
37- override def thenAccept (fn : Consumer [_ >: T ]): CompletableFuture [Void ] = thenAcceptAsync(fn)
39+ override def thenAccept (fn : Consumer [_ >: T ]): CompletableFuture [Void ] = thenAcceptAsync(fn, executor )
3840
39- override def thenRun (fn : Runnable ): CompletableFuture [Void ] = thenRunAsync(fn)
41+ override def thenRun (fn : Runnable ): CompletableFuture [Void ] = thenRunAsync(fn, executor )
4042
41- override def thenCombine [U , V ](cs : CompletionStage [_ <: U ], fn : BiFunction [_ >: T , _ >: U , _ <: V ]): CompletableFuture [V ] = thenCombineAsync(cs, fn)
43+ override def thenCombine [U , V ](cs : CompletionStage [_ <: U ], fn : BiFunction [_ >: T , _ >: U , _ <: V ]): CompletableFuture [V ] = thenCombineAsync(cs, fn, executor )
4244
43- override def thenAcceptBoth [U ](cs : CompletionStage [_ <: U ], fn : BiConsumer [_ >: T , _ >: U ]): CompletableFuture [Void ] = thenAcceptBothAsync(cs, fn)
45+ override def thenAcceptBoth [U ](cs : CompletionStage [_ <: U ], fn : BiConsumer [_ >: T , _ >: U ]): CompletableFuture [Void ] = thenAcceptBothAsync(cs, fn, executor )
4446
45- override def runAfterBoth (cs : CompletionStage [_], fn : Runnable ): CompletableFuture [Void ] = runAfterBothAsync(cs, fn)
47+ override def runAfterBoth (cs : CompletionStage [_], fn : Runnable ): CompletableFuture [Void ] = runAfterBothAsync(cs, fn, executor )
4648
47- override def applyToEither [U ](cs : CompletionStage [_ <: T ], fn : JF [_ >: T , U ]): CompletableFuture [U ] = applyToEitherAsync(cs, fn)
49+ override def applyToEither [U ](cs : CompletionStage [_ <: T ], fn : JF [_ >: T , U ]): CompletableFuture [U ] = applyToEitherAsync(cs, fn, executor )
4850
49- override def acceptEither (cs : CompletionStage [_ <: T ], fn : Consumer [_ >: T ]): CompletableFuture [Void ] = acceptEitherAsync(cs, fn)
51+ override def acceptEither (cs : CompletionStage [_ <: T ], fn : Consumer [_ >: T ]): CompletableFuture [Void ] = acceptEitherAsync(cs, fn, executor )
5052
51- override def runAfterEither (cs : CompletionStage [_], fn : Runnable ): CompletableFuture [Void ] = runAfterEitherAsync(cs, fn)
53+ override def runAfterEither (cs : CompletionStage [_], fn : Runnable ): CompletableFuture [Void ] = runAfterEitherAsync(cs, fn, executor )
5254
53- override def thenCompose [U ](fn : JF [_ >: T , _ <: CompletionStage [U ]]): CompletableFuture [U ] = thenComposeAsync(fn)
55+ override def thenCompose [U ](fn : JF [_ >: T , _ <: CompletionStage [U ]]): CompletableFuture [U ] = thenComposeAsync(fn, executor )
5456
55- override def whenComplete (fn : BiConsumer [_ >: T , _ >: Throwable ]): CompletableFuture [T ] = whenCompleteAsync(fn)
57+ override def whenComplete (fn : BiConsumer [_ >: T , _ >: Throwable ]): CompletableFuture [T ] = whenCompleteAsync(fn, executor )
5658
57- override def handle [U ](fn : BiFunction [_ >: T , Throwable , _ <: U ]): CompletableFuture [U ] = handleAsync(fn)
59+ override def handle [U ](fn : BiFunction [_ >: T , Throwable , _ <: U ]): CompletableFuture [U ] = handleAsync(fn, executor )
5860
5961 override def exceptionally (fn : JF [Throwable , _ <: T ]): CompletableFuture [T ] = {
6062 val cf = new CompletableFuture [T ]
@@ -71,7 +73,7 @@ object FuturesConvertersImpl {
7173 if (n ne this ) cf.complete(n.asInstanceOf [T ])
7274 }
7375 }
74- })
76+ }, executor )
7577 cf
7678 }
7779
0 commit comments