Last active
June 9, 2017 09:46
-
-
Save ikhoon/99dd50414df481b8070c6bb69a5e0635 to your computer and use it in GitHub Desktop.
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
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) | |
} | |
} |
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
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