Skip to content

Commit e781cf0

Browse files
committed
add Scala extension methods for Future conversions
also remove some duplicated dependency on JUnit
1 parent b3fca14 commit e781cf0

File tree

2 files changed

+40
-6
lines changed

2 files changed

+40
-6
lines changed

build.sbt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,6 @@ test in Test := {
3333
(test in Test).value
3434
}
3535

36-
libraryDependencies ++= Seq(
37-
"junit" % "junit" % "4.10" % "test",
38-
"com.novocode" % "junit-interface" % "0.8" % "test"
39-
)
40-
4136
testOptions += Tests.Argument(TestFrameworks.JUnit, "-v", "-a")
4237

4338
sourceGenerators in Compile <+= sourceManaged in Compile map { dir =>
@@ -77,7 +72,7 @@ inConfig(JavaDoc)(Defaults.configSettings) ++ Seq(
7772
javacOptions in JavaDoc := Seq(),
7873
artifactName in packageDoc in JavaDoc := ((sv, mod, art) => "" + mod.name + "_" + sv.binary + "-" + mod.revision + "-javadoc.jar"),
7974
libraryDependencies += compilerPlugin("com.typesafe.genjavadoc" %% "genjavadoc-plugin" % "0.5" cross CrossVersion.full),
80-
scalacOptions <+= target map (t => "-P:genjavadoc:out=" + (t / "java"))
75+
scalacOptions in Compile <+= target map (t => "-P:genjavadoc:out=" + (t / "java"))
8176
)
8277

8378
initialCommands :=
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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

Comments
 (0)