Note : 1) All discussions below are based on the channel type that contains the shaping element, the Chan int
2) My understanding of "<-" is that it may be an operator (receive operator), or
May be part of a type (for example, "chan<-int" means the type of Send channel containing the shaping element)
Channel with Buffering and without cache
1. With cushioning: Ch:=make (Chan int,1)
1) Goruntine A contains the statement ch<-1: To send 1 to CH, if there is already a data in CH, then a is blocked here until the data in CH is taken away;
2) Goruntine A contains the statement <-ch: To receive a data from CH, if there is no data in CH, then a is blocked here until there is data in ch;
3) Assume Ch:=make (Chan int,100), fori: = Range ch {...}. It is important to note that when traversing CH through range:
A. Range loop receives CH, until close (CH), if there is no data, will block here.
B. When close (CH) is run, it is not possible to send data to CH, but can still receive CH remaining data until the data in ch is empty, and the range statement ends instead of blocking.
2. Without buffering: Ch:=make (chan int), at this time the CH only acts as data transfer , cannot store the data (because it does not have buffer).
1) Goruntine A contains ch<-1: Run to here a block immediately unless another goruntine B is executing ch<-
In other words: A want to send data to CH, only when B is ready to receive data from CH;
2) in the same vein, Goruntine A contains <-ch. A to receive a data from CH, only when B is ready to send data to Ch.
type conversion : Be sure to note that Chan int is a whole
<-chan Int (v): Converts v to a channel type and then receives a value from that channel ("<-" is an operator at this point)
(<-chan int) (v): Convert V to a receive Channel type (at which point "<-" is part of the type)
Go:channel (not finished)