File tree Expand file tree Collapse file tree 2 files changed +45
-0
lines changed
22_go-routines/15_for-fun Expand file tree Collapse file tree 2 files changed +45
-0
lines changed Original file line number Diff line number Diff line change 1+ package main
2+
3+ import (
4+ "fmt"
5+ )
6+
7+ func main () {
8+ m := map [int ]int {}
9+ m [4 ] = 7
10+ m [3 ] = 87
11+ m [72 ] = 19
12+
13+ ch := make (chan int )
14+
15+ // for closing ch
16+ ch2 := make (chan int )
17+ go func () {
18+ var i int
19+ for n := range ch2 {
20+ i += n
21+ if i == len (m ) {
22+ close (ch )
23+ }
24+ }
25+ }()
26+
27+ go func () {
28+ for _ , v := range m {
29+ ch <- v
30+ ch2 <- 1
31+ }
32+ }()
33+
34+ for v := range ch {
35+ fmt .Println (v )
36+ }
37+
38+ // good housekeeping
39+ close (ch2 )
40+ }
Original file line number Diff line number Diff line change 1+ # New Code
2+
3+ These files were added into this repo after the training was recorded.
4+
5+ There are no lectures associated with these files. However, please peruse them and enjoy them!
You can’t perform that action at this time.
0 commit comments