登录
首页 >  Golang >  Go问答

chan在golang结构定义中的含义是什么

来源:stackoverflow

时间:2024-02-23 23:54:19 149浏览 收藏

你在学习Golang相关的知识吗?本文《chan在golang结构定义中的含义是什么》,主要介绍的内容就涉及到,如果你想提升自己的开发能力,就不要错过这篇文章,大家要知道编程理论基础和实战操作都是不可或缺的哦!

问题内容

我正在阅读以太坊代码, 下面的意思是什么

<-chan 结构{}chan<-错误

type protoRW struct {
   Protocol
   in     chan Msg        // receives read messages
   closed <-chan struct{} // receives when peer is shutting down
   wstart <-chan struct{} // receives when write may start
   werr   chan<- error    // for write results
   offset uint64
   w      MsgWriter
}

解决方案


struct { ... } 内的列表是 field declarations 的列表。顶部的 Protocol 字段是 embedded field declaration。其余部分使用 格式声明。例如,lined <-chan struct{} 是一个名为 held 的字段,其类型为 <-chan struct{}仅接收 channel,其元素类型为空结构)。 werr chan<- error 是一个名为 werr 的字段,其类型为 chan<- error(一个仅发送通道,其元素类型为 error)。

文中关于的知识介绍,希望对你的学习有所帮助!若是受益匪浅,那就动动鼠标收藏这篇《chan在golang结构定义中的含义是什么》文章吧,也可关注golang学习网公众号了解相关技术文章。

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>