Go Example--通道方向

package main

import "fmt"

func main() {
pings := make(chan string, 1)
pongs := make(chan string, 1)
ping(pings, "passwd message")
pong(pings, pongs)
fmt.Println(<-pongs)
} //只写chan pings
func ping(pings chan<- string, msg string) {
pings <- msg
} //只读chan pings
func pong(pings <-chan string, pongs chan<- string) {
msg := <-pings
pongs <- msg
}
上一篇:windy数(数位DP)


下一篇:OpenGL学习资料汇总