package main import ( "fmt" ) func main() { // Конал создан, но не инициализирован (print вернет nil) /* var c chan int fmt.Println(c) */ // канал - это указатель /* c := make(chan int, 1) fmt.Printf("type of `c` is %T\n", c) fmt.Printf("value of `c` is %v\n", c) go channelReadWrite(c) time.Sleep(1 * time.Second) */ /* fmt.Println("main() started") c := make(chan string) go greet(c) c <- "hello" fmt.Println("main() stopped") */ // /* c := make(chan int) // Здесь будет блокировка горутина main() заблокируется // до тех пор пока не будут считаны данные из канала c <- 1 go channelRead(c) // А так сработает // c <- 1 // */ // time.Sleep(1 * time.Second) } func greet(c chan string) { fmt.Println(<-c) } func channelReadWrite(c chan int) { var data int c <- 77 data = <-c fmt.Println(data) } func channelRead(c chan int) { fmt.Println(<-c) }