channel定义与使用
package main
import "fmt"
func main() {
//定义一个channel
c := make(chan int)
go func() {
defer fmt.Println("goroutine结束")
fmt.Println("goroutine 正在运行...")
c <- 666 //将666 发送给c
}()
num := <-c //从c中接受数据,并赋值给num
fmt.Println("num = ", num)
fmt.Println("main goroutine 结束...")
}
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/tech/pnotes/283092.html