Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Channels

You can think loosely of channels like pipes for fluid - pour it in one end and out at the other.

By including the arrow <- chan or chan <-, you are achieving three things:

  1. You are making it clear that the parameter is one end of a channel.
  2. You are expressing clearly which end is being supplied.
  3. You are giving more information to the compiler for checking. If the function body tries to use the wrong end of the channel, the compiler can raise an error. These are good reasons to show the channel end whenever possible.
when you see which end is of the channel is it for?
chan <- writing to channel (output channel)
<- chan reading from channel (input channel)
chan read from or write to channel (input/output channel)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment