Channels
A channel is a typed conduit/tube through which we send and receive values with the channel operator <-
.
We can create channels similar to creating maps and slices using the make
function:
By default, sends and receives block until the other side is ready. This allows goroutines to synchronize without explicit locks or condition variables.
Example
Buffered Channels
Channels can be buffered. Provide the buffer length as the second argument to make
to initialize a buffered channel:
Sends to a buffered channel block only when the buffer is full. Receives block when the buffer is empty.
Example
Last updated
Was this helpful?