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 才对呀
看不明白
1
buffzty 2021-05-19 09:01:55 +08:00
你看一下 puxu 里面是咋写的 都有注释 看了你就明白了
|