Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use channel in golang

Shulou Source: shulou.com Published: 2022-06-01 05:17:56 10月15日 Update

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

Tags: Data code buffer deadlock fragment buffer block output program run loop one-way sender pipe receiver memory area synchronization example only finished Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info MariaDB vpn MySQL Docker