Created
December 30, 2015 06:45
-
-
Save chrisphelps/43fb1b2bd5d958728167 to your computer and use it in GitHub Desktop.
Conversion from guava ListenableFuture to Scala Future
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
implicit def toScalaFuture[T](lFuture: ListenableFuture[T]): Future[T] = { | |
val p = Promise[T] | |
Futures.addCallback(lFuture, | |
new FutureCallback[T] { | |
def onSuccess(result: T) = p.success(result) | |
def onFailure(t: Throwable) = p.failure(t) | |
}) | |
p.future | |
} |
import com.google.common.util.concurrent.{FutureCallback, Futures, ListenableFuture}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
what are the correct import(s) ?