go-concurrency101/basics/flow-control/main.go

46 lines
546 B
Go

package main
import "fmt"
func walk(ch1, ch2 chan int) {
fmt.Println("walk")
fmt.Println("1")
ch1 <- 2
fmt.Println("2")
y := <-ch2
fmt.Println("y=", y)
fmt.Println("3")
}
func loadWorker(ch1, ch2 chan int) {
fmt.Println("loadWorker")
fmt.Println("4")
select {
case x := <-ch1:
fmt.Println("x=", x)
fmt.Println("5")
select {
case ch2 <- x + 5:
fmt.Println("6")
}
}
fmt.Println("7")
}
func main() {
ch1 := make(chan int)
ch2 := make(chan int)
go loadWorker(ch1, ch2)
walk(ch1, ch2)
fmt.Println("Done")
}