讓頻道保持開放可以嗎? - 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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章