This is a creation in Article, where the information may have evolved or changed.
- Go language
- Interface
- Concurrent
- Channel
- Buffered Channels
Go language
Interface
A combination of a group of method
typeinterface { SayHi() string)}var i Meni = mike
- As long as the struct that implements all the functions in interface can be assigned to I;
- The function of the abstract base class in C + + can be realized by taking interface as the parameter of functions.
- Value, OK = element. (T) upcasting;
- Reflection T: = Reflect. Typeof (i)
Concurrent
Goroutine: Smaller-grained units than threads
go hello(a, b, c)
- The Go keyword launches a goroutine
- Goexit (defer function is still called)
- Gosched (Give up CPU time)
Channel
Communication of Goroutine
make(chanint)ch <- v # 把 v 发给 chv := <- ch # 从 ch 收信
- The assignment and reading values of the default ch are blocked;
Buffered Channels
CH: = Make (chan bool, 4)
* So the first four elements, do not block; The first element begins to block;
* range can be used to foreach Channel
* Close can show closed channel no longer receives message;
* Select (Linux-like Select);
* Select monitors multiple channels simultaneously;
copyright notice: This article for Bo Master original article, without Bo Master permission not reproduced.