channel
- 管道,類似unix/linux中的pipe
- 多個goroute之間通過channel進行通信
- 支持任何類型
func main() {
pipe := make(chan int,3)
pipe <- 1
pipe <- 2
}
example-01
package main
import(
"fmt"
)
func main() {
test_pipe()
}
func test_pipe(){
pipe := make(chan int, 3)
pipe <- 11
pipe <- 7
pipe <- 73
var t1 int
t1 =<- pipe
//pipe <- 33
fmt.Println(len(pipe)) // 2
fmt.Println(t1) // 11
}