By default channels are
unbuffered
, meaning that they
will only accept sends (
chan <-
) if there is a
corresponding receive (
<- chan
) ready to receive the
sent value.
Buffered channels
accept a limited
number of values without a corresponding receiver for
those values.
packagemain
import"fmt"
funcmain(){
Here we
make
a channel of strings buffering up to
2 values.
messages:=make(chanstring,2)
Because this channel is buffered, we can send these
values into the channel without a corresponding
concurrent receive.