Skip to content

Instantly share code, notes, and snippets.

@sam
Created September 23, 2015 20:51
Show Gist options
  • Save sam/14971438ef77a13f53f0 to your computer and use it in GitHub Desktop.
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.
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