Skip to content

Instantly share code, notes, and snippets.

@mfirry
Created April 27, 2015 17:13
Show Gist options
  • Save mfirry/8505ae6316ea59410562 to your computer and use it in GitHub Desktop.
Save mfirry/8505ae6316ea59410562 to your computer and use it in GitHub Desktop.
DO NOT DO IT! silly example of handling to/fro Twitter Utils' Future to Scala Futures (using https://github.com/twitter/bijection)
import com.twitter.bijection.twitter_util.UtilBijections._
import com.twitter.bijection.{ AbstractBijection, Bijection, ImplicitBijection }
import com.twitter.util.Future
import scala.concurrent._
import scala.concurrent.ExecutionContext.Implicits.global
//let's create two futures and put them in a List
val a = com.twitter.util.Future(1)
val b = com.twitter.util.Future(2)
//a list of com.twitter.util.Future[Int]
val ltf = List(a, b)
//a list of scala.concurrent.Future[Int]
val lf = ltf map { f => Bijection[com.twitter.util.Future[Int], scala.concurrent.Future[Int]](f) }
//a scala.concurrent.Future[List[Int]]
val fl = scala.concurrent.Future.sequence(lf)
//a com.twitter.util.Future[List[Int]]
val tfl = Bijection[scala.concurrent.Future[List[Int]], com.twitter.util.Future[List[Int]]](res1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment