Skip to content

Instantly share code, notes, and snippets.

@vkostyukov
Last active August 29, 2015 13:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vkostyukov/10164245 to your computer and use it in GitHub Desktop.
Save vkostyukov/10164245 to your computer and use it in GitHub Desktop.
/**
* 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