Skip to content

Instantly share code, notes, and snippets.

@davidhoyt
davidhoyt / scala-future-to-java-future.scala
Created November 22, 2013 21:49
Converts from a scala.concurrent.Future to a java.util.concurrent.Future
import scala.util._
import scala.concurrent._
import java.util.concurrent.{Callable, FutureTask}
object Utils {
def toJavaFuture[TScalaType, TJavaType](f: Future[TScalaType])(map: (TScalaType => TJavaType))(implicit executor: ExecutionContext): java.util.concurrent.Future[TJavaType] = {
val applied = f.map(map)
val task = new FutureTask[TJavaType](new Callable[TJavaType] {
def call(): TJavaType = applied.value.get match {