github.com/graybobo/golang.org-package-offline-cache@v0.0.0-20200626051047-6608995c132f/x/talks/2015/go4cpp/chan.go (about) 1 // +build OMIT 2 3 package main 4 5 import ( 6 "fmt" 7 "time" 8 ) 9 10 func sleepAndTalk(secs time.Duration, msg string, c chan string) { 11 time.Sleep(secs * time.Second) 12 c <- msg 13 } 14 15 func main() { 16 c := make(chan string) 17 18 go sleepAndTalk(0, "Hello", c) 19 go sleepAndTalk(1, "Gophers!", c) 20 go sleepAndTalk(2, "What's", c) 21 go sleepAndTalk(3, "up?", c) 22 23 for i := 0; i < 4; i++ { 24 fmt.Printf("%v ", <-c) 25 } 26 }