In last part, where we discussed Golang Concurrency, 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 Golang Concurrency - Part 1, 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
Generally 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
Select work like a case switch for channels, basic construct looks like:
Happy Channeling :)
About The Author
I am Pankaj Baagwan, a System Design Architect. A Computer Scientist by heart, process enthusiast, and open source author/contributor/writer. Advocates Karma. Love working with cutting edge, fascinating, open source technologies.
To consult Pankaj Bagwan on System Design, Cyber Security and Application Development, SEO and SMO, please reach out at me[at]bagwanpankaj[dot]com
For promotion/advertisement of your services and products on this blog, please reach out at me[at]bagwanpankaj[dot]com
Stay tuned <3. Signing off for RAAM