Channels in Golang

Channel is an important feature in Golang.
It is one of the features that make Golang unique.
It makes concurrent programming easier (at least looks), flexible and fun,

This article will list all the channel related concepts, syntaxes and rules.

Channel Concepts And Syntaxes

Channel Introduction

A channel can be viewed as a FIFO (first in, first out) message queue in a program internal.
The purpose of using channels is to transfer values,
more accurately, to transfer ownerships of values, between goroutines.
A well designed program should make sure most one goroutine can have the ownership of any value at any time.
By using channels properly, data races between goroutines can be avoided.

Channel Types And Values

Channel types are composite types. Like array, slice and map,
a specified channel type has an element type.
All data to be pushed into the channel must be values of the element type.
For example, if the element type is string,
then the channel type is

Original URL:

Original article

Comments are closed.

Proudly powered by WordPress | Theme: Baskerville 2 by Anders Noren.

Up ↑

%d bloggers like this: