Golang Go语言中 tomb 是怎么起作用的?

Golang Go语言中 tomb 是怎么起作用的?

kill 的内部实现是这个样子


func (t *Tomb) kill(reason error) {
	if reason == ErrStillAlive {
		panic("tomb: Kill with ErrStillAlive")
	}
	if reason == ErrDying {
		if t.reason == ErrStillAlive {
			panic("tomb: Kill with ErrDying while still alive")
		}
		return
	}
	if t.reason == ErrStillAlive {
		t.reason = reason
		close(t.dying)
		for _, child := range t.child {
			child.cancel()
		}
		t.child = nil
		return
	}
	if t.reason == nil {
		t.reason = reason
		return
	}
}

那按理来讲 <-tomb.Dying() 应该永远 block 才对呀

看不明白


更多关于Golang Go语言中 tomb 是怎么起作用的?的实战教程也可以访问 https://www.itying.com/category-94-b0.html

回到顶部