Go to Go - Concurrency Part#216 Mar 2014
In last part, we talked about
goroutines and channels. As discussed there is much more to channels, liked channel direction, by default a channel is bi-directional, but it can be restricted to sending or receiving.
In sender, receiver example from part, sender can only be restricted to sending, by redifining it like
Now sender can only send signal to channel
ch. Similarly receiver can be restricted just to receive, by redifining it like
Buffering in channels
channels are synchronous, but they can have buffer of specified size. Buffer size can be specified by passing a second argument while creating a channel
Now this channel can buffer at most 10 messages, working as a pub/sub.
Select work like a case switch for channels, basic construct looks like:
Happy Channeling :)