Last active
August 29, 2015 13:58
-
-
Save vkostyukov/10164245 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* Reactive Converter of Scala's Future[A] object to com.twitter.util.Future[A] object. | |
* | |
* Usage: | |
* | |
* val s = new Service[Req, Rep] with FutureConverter { | |
* def apply(req: Req): Future[Rep] = { | |
* val f = ... // a Scala Future | |
* f.toTwitterFuture | |
* } | |
* } | |
*/ | |
import scala.concurrent.{Future => ScalaFuture} | |
import com.twitter.util.{Promise, Future} | |
trait FutureConverter { | |
implicit class ScalaToTwitter[A](f: ScalaFuture[A]) { | |
def toTwitterFuture: Future[A] = { | |
val p = Promise[A] | |
f.onComplete { | |
case Success(result) => p.setValue(result) | |
case Failure(t) => p.setException(t) | |
} | |
p | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment