import (
"fmt"
"strconv"
"time"
)
func add(a, b int) int {
time.Sleep(100 * time.Millisecond)
return a + b
}
func startGoroutine() {
result := add(3, 5)
fmt.Println("result: " + strconv.Itoa(result))
}
go startGoroutine()
fmt.Println("main thread")
// main 必须在 goroutine 结束之后才能退出,
// 否则程序会在打印 "result: 8" 之前结束
time.Sleep(time.Second)
//输出:
//main thread
//result: 8