Created
May 2, 2013 18:45
-
-
Save arschles/5504373 to your computer and use it in GitHub Desktop.
Converting a Twitter future to a Scala Future
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
import com.twitter.util.{Future => TwFuture} | |
import scala.concurrent.{Future => ScFuture, promise => scPromise} | |
implicit def twFutureToScala[T](twFuture: TwFuture[T]): ScFuture[T] = { | |
val prom = scPromise[T] | |
twFuture.onComplete { res: T => | |
prom.success(res) | |
} | |
twFuture.onFailure { t: Throwable => | |
prom.failure(t) | |
} | |
prom | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment