Skip to content

Instantly share code, notes, and snippets.

@yllan
Last active August 29, 2015 13:56
Show Gist options
  • Select an option

  • Save yllan/9099000 to your computer and use it in GitHub Desktop.

Select an option

Save yllan/9099000 to your computer and use it in GitHub Desktop.
Welcome to Scala version 2.10.3 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_45).
Type in expressions to have them evaluated.
Type :help for more information.
scala> import scala.concurrent._
import scala.concurrent._
scala> import scala.concurrent.duration._
import scala.concurrent.duration._
scala> import ExecutionContext.Implicits.global
import ExecutionContext.Implicits.global
scala>
| val i = (1 to 100).toIterator.map(x => Future { for (i <- 0 to 100000000) { i + 1 }; println(s"$x done"); x + 1 })
i: Iterator[scala.concurrent.Future[Int]] = non-empty iterator
scala> val f = Future.sequence(i)
f: scala.concurrent.Future[Iterator[Int]] = scala.concurrent.impl.Promise$DefaultPromise@7ca89faf
scala> 2 done
3 done
1 done
4 done
5 done
6 done
8 done
7 done
9 done
11 done
10 done
12 done
13 done
14 done
15 done
16 done
19 done
18 done
17 done
20 done
23 done
21 done
22 done
24 done
25 done
26 done
27 done
28 done
29 done
31 done
30 done
32 done
35 done
33 done
34 done
36 done
37 done
38 done
39 done
40 done
41 done
42 done
43 done
44 done
45 done
46 done
47 done
48 done
50 done
49 done
51 done
52 done
54 done
53 done
55 done
56 done
57 done
58 done
59 done
60 done
61 done
62 done
63 done
64 done
66 done
65 done
67 done
68 done
69 done
70 done
71 done
72 done
73 done
74 done
75 done
76 done
77 done
78 done
79 done
80 done
81 done
82 done
83 done
84 done
85 done
86 done
87 done
88 done
89 done
90 done
91 done
92 done
93 done
94 done
95 done
96 done
97 done
98 done
99 done
100 done
import scala.concurrent._
import scala.concurrent.duration._
import ExecutionContext.Implicits.global
val i = (1 to 100).toIterator.map(x => Future { for (i <- 0 to 100000000) { i + 1 }; println(s"$x done"); x + 1 })
val f = Future.sequence(i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment