concurrency.mx raw
1 // transpiled from Go by mx-transpile - review TODOs before use
2
3 package example
4
5 func worker(id int, results chan<- int) {
6 results <- id * id
7 }
8
9 func fanOut() {
10 results := make(chan int)
11 for i := 0; i < 4; i++ {
12 spawn worker(i, results)
13 }
14 for i := 0; i < 4; i++ {
15 <-results
16 }
17 }
18
19 func background(fn func()) {
20 spawn fn()
21 }
22
23 func pipeline() {
24 ch := make(chan []byte)
25 spawn func() {
26 ch <- "hello"
27 }()
28 msg := <-ch
29 _ = msg
30 }
31