Created
September 23, 2015 20:51
-
-
Save sam/14971438ef77a13f53f0 to your computer and use it in GitHub Desktop.
Demonstrating Future.sequence always returns the mapped Sequence in the same order it was passed.
This file contains hidden or 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.ExecutionContext.Implicits.global | |
import scala.concurrent.Future | |
val a = Future { 1 } // completes immediately. | |
val b = Future { Thread.sleep(1000); 2 } // is the last to complete. | |
val c = Future { Thread.sleep(100); 3 } // completes after 1 but before 2. | |
Future.sequence(Seq(a, b, c)) map println | |
// > List(1, 2, 3) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment