golang 只读/只写channel

2,194 阅读1分钟
//可同时读写
go func(num int, close chan struct{}) {
    <-close
    close <- struct{}{}
}(i,c)

//只写channel
go func(num int, close chan<- struct{}) {
    <-close //error
    close <- struct{}{}
}(i,c)

//只读channel
go func(num int, close <-chan struct{}) {
    <-close
    close <- struct{}{} //error
}(i, c)