Left: | ||
Right: |
OLD | NEW |
---|---|
(Empty) | |
1 package main | |
2 | |
3 import ( | |
4 "fmt" | |
5 "time" | |
6 ) | |
7 | |
8 func sleepAndTalk(secs time.Duration, msg string, c chan string) { | |
9 time.Sleep(secs * time.Second) | |
10 c <- msg | |
11 } | |
12 | |
13 func main() { | |
14 c := make(chan string) | |
15 | |
16 go sleepAndTalk(0, "Hello", c) | |
17 go sleepAndTalk(1, "Gophers!", c) | |
18 go sleepAndTalk(2, "What's", c) | |
19 go sleepAndTalk(3, "up?", c) | |
20 | |
21 for i := 0; i < 4; i++ { | |
22 fmt.Printf("%v ", <-c) | |
23 } | |
24 } | |
OLD | NEW |