让频道保持开放可以吗? - Is it OK to leave a channel open?

问题:

Is it OK to leave a Go channel open forever (never close the channel) if I never check for its state?如果我从不检查其状态,是否可以让 Go 通道永远打开(永远不要关闭通道)? Will it lead to memory leaks?会导致内存泄漏吗? Is the following code OK?下面的代码好吗?

func (requestCh chan<- Request) GetResponse(data RequestData) Response {
    reply := make(chan Response)
    requestCh <- Request{data: data, replyCh: reply}
    return <-reply
}

解决方案:

参考一: https://en.stackoom.com/question/a3bB
参考二: https://stackoom.com/question/a3bB
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章