Skip to content

Instantly share code, notes, and snippets.

@ikhoon
Last active June 9, 2017 09:46
Show Gist options
  • Save ikhoon/99dd50414df481b8070c6bb69a5e0635 to your computer and use it in GitHub Desktop.
Save ikhoon/99dd50414df481b8070c6bb69a5e0635 to your computer and use it in GitHub Desktop.
object TwiiterScalaFutureOps {
import TwitterScalaFutureConverters._
implicit class ScalaToTwitterFuture[T](f: Future[T]) {
def toTwitterFuture: twitter.Future[T] = scalaToTwitterFuture(f)
}
implicit class TwitterToScalaFuture[T](f: twitter.Future[T]) {
def toScalaFuture: Future[T] = twitterToScalaFuture(f)
}
}
object TwitterScalaFutureConverters {
implicit def scalaToTwitterTry[T](t: Try[T]): twitter.Try[T] = t match {
case Success(r) => twitter.Return(r)
case Failure(ex) => twitter.Throw(ex)
}
implicit def twitterToScalaTry[T](t: twitter.Try[T]): Try[T] = t match {
case twitter.Return(r) => Success(r)
case twitter.Throw(ex) => Failure(ex)
}
implicit def scalaToTwitterFuture[T](f: Future[T])(implicit ec: ExecutionContext): twitter.Future[T] = {
val promise = twitter.Promise[T]()
f.onComplete(promise update _)
promise
}
implicit def twitterToScalaFuture[T](f: twitter.Future[T]): Future[T] = {
val promise = Promise[T]()
f.respond(promise complete _)
promise.future
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment