課題
make で channel を使ったときのデフォルト値が気になった。
quit := make(chan os.Signal)
普段はキャパシティとかが後につくけど、これはどういうことだろう?デフォルト値は?
定義
こちらにこんな表があった。
Call Type T Result
make(T, n) slice slice of type T with length n and capacity n
make(T, n, m) slice slice of type T with length n and capacity m
make(T) map map of type T
make(T, n) map map of type T with initial space for approximately n elements
make(T) channel unbuffered channel of type T
make(T, n) channel buffered channel of type T, buffer size n
make は3つに大きくわかれているのですな。make(T) は、「バッファされない」がデフォルトのようです。
気になったのでソースコードを読んでいると、同じくコメントでありました。
// Channel: The channel's buffer is initialized with the specified
// buffer capacity. If zero, or the size is omitted, the channel is
// unbuffered.
すっきり。