1. Goroutines and channels
A goroutine is created every time it is executed go func()
, including the function and context information to be executed.
Goroutine is the concurrent execution of Go programs channel
and the communication channel between them.
var ch1 chan int. //declare an integer channel
2. Channel common operations
//Define a channel
channel :=make(chan int)
//Send value to channel
channel <- 10
//Receive the value and assign it to the variable x
x:= <- channel
//Closeclose
(channel)
3. select
Keyword, responding to multiple channel operations at the same time
select { case v1<-channel1: //... case v2 := <-channel2: //... case channel3 <- 10: //... default: //default operation }