go 提前退出

go - 退出语句

主要分为: return 、Exit、Goexit

用例代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package main
 
import (
    "fmt"
    "runtime"
    "time"
)
 
/*
 
return             退出当前函数
os.Exit(-1)        退出当前进程(程序)
runtime.Goexit()   退出当前go程,只退出最近一层
 
*/
 
 
func main() {
    go func() {
        go func() {
            fmt.Print("this is go 11111\n")
            // return
            // os.Exit(-1)
            runtime.Goexit()
            fmt.Print("this is go 22222\n")
        }()
        time.Sleep(1*time.Second)
        fmt.Print("this is go 3333\n")
    }()
    time.Sleep(2 * time.Second)
    fmt.Print("this is 主进程\n")
}

 

posted @   萤huo虫  阅读(70)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
历史上的今天:
2018-09-13 Python基本数据类型
点击右上角即可分享
微信分享提示