5 ms·
Channels by themselves are not a concurrency primitive. If you try to write and read from a channel in the same context, you'll deadlock. Goroutines (or "go blo
by alco 13y ago
Channels by themselves are not a concurrency primitive. If you try to write and read from a channel in the same context, you'll deadlock. Goroutines (or "go blocks") provide the concurrent semantics, channels are a means of communication.
In Go you don't actually ask "what channel do I read from?". You are handed a channel (as a function argument or as a value from another channel) which you can then use to communicate. From the encapsulation point of view, pids and channels are very similar -- the code using the channel/pid doesn't have to know anything about the other end.
But the semantics of channels and message passing are very different: always synchronous vs asynchronous by default.