35 lines
547 B
Go
35 lines
547 B
Go
package main
|
|
|
|
import "fmt"
|
|
|
|
func main() {
|
|
/*
|
|
1、声明chan类型
|
|
*/
|
|
var ch1 chan int
|
|
fmt.Println(ch1)
|
|
//只写通道
|
|
var ch2 chan<- string
|
|
fmt.Println(ch2)
|
|
//只读通道
|
|
var ch3 <-chan int
|
|
fmt.Println(ch3)
|
|
|
|
chll := make(chan string, 3)
|
|
fmt.Println(chll)
|
|
//创建一个只读
|
|
ch12 := make(<-chan int)
|
|
//创建一个只写
|
|
ch13 := make(chan<- int)
|
|
fmt.Println(ch12)
|
|
fmt.Println(ch13)
|
|
go func() {
|
|
chll <- "你好1"
|
|
chll <- "你好2"
|
|
chll <- "你好3"
|
|
}()
|
|
fmt.Println(<-chll)
|
|
fmt.Println(<-chll)
|
|
fmt.Println(<-chll)
|
|
}
|