@@ -23,7 +23,9 @@ import scala.util.{Failure, Success, Try}
23
23
24
24
// TODO: make this private[scala] when genjavadoc allows for that.
25
25
object 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
+
27
29
override def apply (t : Try [T ]): Unit = t match {
28
30
case Success (v) => complete(v)
29
31
case Failure (e) => completeExceptionally(e)
@@ -32,29 +34,29 @@ object FuturesConvertersImpl {
32
34
/*
33
35
* Ensure that completions of this future cannot hold the Scala Future’s completer hostage.
34
36
*/
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 )
36
38
37
- override def thenAccept (fn : Consumer [_ >: T ]): CompletableFuture [Void ] = thenAcceptAsync(fn)
39
+ override def thenAccept (fn : Consumer [_ >: T ]): CompletableFuture [Void ] = thenAcceptAsync(fn, executor )
38
40
39
- override def thenRun (fn : Runnable ): CompletableFuture [Void ] = thenRunAsync(fn)
41
+ override def thenRun (fn : Runnable ): CompletableFuture [Void ] = thenRunAsync(fn, executor )
40
42
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 )
42
44
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 )
44
46
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 )
46
48
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 )
48
50
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 )
50
52
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 )
52
54
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 )
54
56
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 )
56
58
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 )
58
60
59
61
override def exceptionally (fn : JF [Throwable , _ <: T ]): CompletableFuture [T ] = {
60
62
val cf = new CompletableFuture [T ]
@@ -71,7 +73,7 @@ object FuturesConvertersImpl {
71
73
if (n ne this ) cf.complete(n.asInstanceOf [T ])
72
74
}
73
75
}
74
- })
76
+ }, executor )
75
77
cf
76
78
}
77
79
0 commit comments