channel的test1,基础
This commit is contained in:
parent
bba7ffe503
commit
4105f63f1f
20
bilibili/aceld/goroutine/channel/test1/main.go
Normal file
20
bilibili/aceld/goroutine/channel/test1/main.go
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import "fmt"
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
// 定义一个channel
|
||||||
|
c := make(chan int)
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
defer fmt.Println("goroutine 结束")
|
||||||
|
fmt.Println("goroutine 正在运行...")
|
||||||
|
// 将值发送给c
|
||||||
|
c <- 666
|
||||||
|
}()
|
||||||
|
|
||||||
|
// 读c中的数据并赋值给num
|
||||||
|
num := <-c
|
||||||
|
fmt.Println("num = ", num)
|
||||||
|
fmt.Println("main goroutine 结束 ...")
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user