Skip to content

Instantly share code, notes, and snippets.

@lloydmeta
Last active August 29, 2016 22:59
Show Gist options
  • Save lloydmeta/13346214f913eb41ea36 to your computer and use it in GitHub Desktop.
Save lloydmeta/13346214f913eb41ea36 to your computer and use it in GitHub Desktop.
Implicit conversion from a Twitter Future to a Scala Future
import com.twitter.util.{Future => TwitterF}
import scala.concurrent.{Future => ScalaF, Promise => ScalaP}
object TwitterFutureSupport {
/**
Implicit conversion from a Twitter Future to a Scala Future
**/
implicit def twitterFutureToScalaFuture[T](twitterF: TwitterF[T]): ScalaF[T] = {
val scalaP = ScalaP[T]
twitterF.onSuccess { r: T =>
scalaP.success(r)
}
twitterF.onFailure { e: Throwable =>
scalaP.failure(e)
}
scalaP.future
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment