您好,登錄后才能下訂單哦!
坑,以下例子中,原本以為close掉done channel后,循環會退出。但事實上會進入死循環
for {
select {
case packet := <-s.avPacketChan:
s.sendPacket(packet)
case <-s.done: //終止channel
break
}
}
原因:
[A "break" statement terminates execution of the innermost "for", "switch" or "select" statement.
官方文檔](https://golang.org/ref/spec#Break_statements)
BreakStmt = "break" [ Label ] .
If there is a label, it must be that of an enclosing "for", "switch" or "select" statement, and that is the one whose execution terminates (§For statements, §Switch statements, §Select statements).
L:
for i < n {
switch i {
case 5:
break L // 從L標簽處開始執行
}
}
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。