美文网首页
goroutine Goexit()

goroutine Goexit()

作者: 来到了没有知识的荒原 | 来源:发表于2020-07-18 11:53 被阅读0次

退出当前goroutine

package main

import (
    "fmt"
    "runtime"
    "time"
)

func main() {

    go func(){
        fmt.Println("before...")
        fun()
        fmt.Println("after...")
    }()
    time.Sleep(time.Second)
}


func fun(){
    defer fmt.Println("defer...")
    runtime.Goexit()
    fmt.Println("fun...")
}

相关文章

网友评论

      本文标题:goroutine Goexit()

      本文链接:https://www.haomeiwen.com/subject/bnvxkktx.html