Skip to content

Instantly share code, notes, and snippets.

@jenglert
Created August 6, 2014 18:12
Show Gist options
  • Save jenglert/731586eae54a5452d00e to your computer and use it in GitHub Desktop.
Save jenglert/731586eae54a5452d00e to your computer and use it in GitHub Desktop.
scala> import scala.concurrent._
import scala.concurrent._
scala> import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.ExecutionContext.Implicits.global
scala> import scala.concurrent.duration._
import scala.concurrent.duration._
scala> val f1 = future { Thread.sleep(10000000000l); "a" }
warning: there were 1 deprecation warning(s); re-run with -deprecation for details
f1: scala.concurrent.Future[String] = scala.concurrent.impl.Promise$DefaultPromise@379e3bdb
scala> val f2 = future { "b" }
warning: there were 1 deprecation warning(s); re-run with -deprecation for details
f2: scala.concurrent.Future[String] = scala.concurrent.impl.Promise$DefaultPromise@8c24496
scala> val f3 = future { "c" }
warning: there were 1 deprecation warning(s); re-run with -deprecation for details
f3: scala.concurrent.Future[String] = scala.concurrent.impl.Promise$DefaultPromise@7d2ba6d7
scala> val combinedFuture = Future.sequence(List(f1, f2, f3))
combinedFuture: scala.concurrent.Future[List[String]] = scala.concurrent.impl.Promise$DefaultPromise@5ddfba0e
scala> Await.result(combinedFuture, 10.seconds)
java.util.concurrent.TimeoutException: Futures timed out after [10 seconds]
at scala.concurrent.impl.Promise$DefaultPromise.ready(Promise.scala:219)
at scala.concurrent.impl.Promise$DefaultPromise.result(Promise.scala:223)
at scala.concurrent.Await$$anonfun$result$1.apply(package.scala:111)
at scala.concurrent.BlockContext$DefaultBlockContext$.blockOn(BlockContext.scala:53)
at scala.concurrent.Await$.result(package.scala:111)
... 32 elided
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment