go_study/bilibili/aceld/goroutine/channel/test1/main.go

21 lines
369 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package main
import "fmt"
func main() {
// 定义一个channel
c := make(chan int)
go func() {
defer fmt.Println("goroutine 结束")
fmt.Println("goroutine 正在运行...")
// go程中将值发送给c
c <- 666
}()
// 主线程中读c中的数据并赋值给num
num := <-c
fmt.Println("num = ", num)
fmt.Println("main goroutine 结束 ...")
}