Go 协程 goroutine

Go About 252 words

go 关键字

在调用方法或函数时,添加go关键字,即表示该方法或函数运行在协程中。

func main() {
    println("start")
    go Goroutine()
    println("end")

    time.Sleep(time.Second * 5)
}

func Goroutine() {
    time.Sleep(time.Second * 3)
    println("goroutine")
}

输出

start
end
goroutine
Views: 310 · Posted: 2023-09-22

————        END        ————

Give me a Star, Thanks:)

https://github.com/fendoudebb/LiteNote

扫描下方二维码关注公众号和小程序↓↓↓

扫描下方二维码关注公众号和小程序↓↓↓


Today On History
Browsing Refresh