中級 › send on closed channel パニックの原因と直し方 › パターン4
send on closed channel パニックの原因と直し方
close()で閉じた後のチャネルに値を送信しようとすると、実行時にパニックが発生します。
1 package main 2 3 func main() { 4 ch := make(chan int, 3) 5 close(ch) 6 _________ ^ 7 }
panic: send on closed channel
空欄を埋めて実行を通す
バッファの容量に関わらず、closeされたチャネルへの送信は常にパニックの対象です。
次の問題