3

go 中,进程退出如何保障异步协程的完整退出。

 1 year ago
source link: https://www.v2ex.com/t/889105
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

V2EX  ›  Go 编程语言

go 中,进程退出如何保障异步协程的完整退出。

  ml444 · 2 小时 3 分钟前 · 244 次点击

写了一个 go 的异步 log 组件。为了保障异步的 channel 被彻底消费完,我增加了Exit()函数,但我想让调用无感知,不用刻意去调用这个函数。有没有什么办法或方式能够实现?

package main

import (
	"os"
	
	"github.com/ml444/glog"
)

func main() {
	// doing something
	log.Info("hello world")
	// doing something

	_ = log.Exit()

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK