Skip to content

Instantly share code, notes, and snippets.

@mathhun
Created July 7, 2016 02:11
Show Gist options
  • Save mathhun/8bc0d260ac7c43004c72c57341dba585 to your computer and use it in GitHub Desktop.
Save mathhun/8bc0d260ac7c43004c72c57341dba585 to your computer and use it in GitHub Desktop.
Future.sequence
import scala.concurrent._
import scala.concurrent.duration._
import scala.concurrent.ExecutionContext.Implicits.global
object Main extends App {
val fs: List[Future[Int]] = List(
Future { Thread.sleep(2000); println(1); 1 },
Future { Thread.sleep(1000); println(2); 2 },
Future { Thread.sleep(3000); println(3); 3 }
)
val start = System.currentTimeMillis
val x: Future[List[Int]] = Future.sequence(fs)
val y = Await.ready(x, Duration.Inf)
println(y)
println(System.currentTimeMillis - start)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment