Created
July 7, 2016 02:11
-
-
Save mathhun/8bc0d260ac7c43004c72c57341dba585 to your computer and use it in GitHub Desktop.
Future.sequence
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 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