com.github.thanhtien522.TwitterConverters.scala Maven / Gradle / Ivy
package com.github.thanhtien522
import com.twitter.{util => twitter}
import scala.concurrent.{ExecutionContext, Future}
import scala.language.implicitConversions
import scala.util.{Failure, Success, Try}
object TwitterConverters {
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
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy