最近发布的主题
暂无
最近发布的文章
最近分享的资源
暂无
最近发布的项目
暂无
最近的评论
-
评论了博文 关于定义单向读channel的问题@txg5214 timeout := make(chan bool, 1) go func() { time.Sleep(1e9) timeout <- true }() ch := make(chan int) onlyWrite := chan<- int(ch) onlyRead := <-chan int(ch) select { case onlyWrite <- 1: fmt.Println("write success") case <- onlyRead: fmt.Println("read success") case <-timeout: fmt.Println("stop") } 上面的代码编译的时候就会报错 invalid operation: <-onlyRead (receive from non-chan type int)