V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
simple2025
0D

golang 的 tomb 怎么起作用的?

  •  
  •   simple2025 · May 18, 2021 · 1431 views
    This topic created in 1817 days ago, the information mentioned may be changed or developed.

    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 replies    2021-05-19 09:01:55 +08:00
    buffzty
        1
    buffzty  
       May 19, 2021
    你看一下 puxu 里面是咋写的 都有注释 看了你就明白了
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   909 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 21:30 · PVG 05:30 · LAX 14:30 · JFK 17:30
    ♥ Do have faith in what you're doing.