How to use channel in golang
Today, the editor will share with you the relevant knowledge points about how to use channel in golang. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article. Let's take a look at it.
What is the channel pipeline?
It is a data pipeline in which you can write data and read data from it.
Channel is a data communication bridge between goroutine and is thread-safe.
Channel follows the first-in, first-out principle.
Both write and read data will be locked.
Channel can be divided into three types:
Read-only channel, unidirectional channel
Write only channel, one-way channel
Readable and writable channel
Channel can also be divided according to whether there is a buffer or not:
Channel with buffer, which defines the buffer size and can store multiple data
Channel with no buffer can only store one data, and the next data can be saved only when the data is taken out.
Basic usage definition and declaration of channel / / read-only channelvar readOnlyChan