go_study/bilibili/aceld/goroutine/test2/main.go

35 lines
767 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"
"time"
)
func main() {
// 用go创建承载一个形参为空返回值为空的一个函数
// go func() {
// defer fmt.Println("A.defer")
// // 如果go程强制退出
// // return
// func() {
// defer fmt.Println("B.defer")
// // 直接return只会退出当前子函数并没有退出goroutin
// // return
// // 用runtion.Goexit()会退出当前goroutine效果就是fmt.Println("A")不会被执行)
// runtime.Goexit()
// fmt.Println("B")
// }() // 结尾的小括号表示定义匿名函数后立即调用这个函数
// fmt.Println("A")
// }()
go func(a int, b int) bool {
fmt.Println("a = ", a, ", b = ", b)
return false
}(10, 20)
for {
time.Sleep(1 * time.Second)
}
}