Last active
August 29, 2016 22:59
-
-
Save lloydmeta/13346214f913eb41ea36 to your computer and use it in GitHub Desktop.
Implicit conversion from a Twitter Future to a Scala Future
This file contains hidden or 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
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