GoExpertProgramming
GoExpertProgramming copied to clipboard
timer.Stop() 返回值的解释貌似有误
https://github.com/RainbowMango/GoExpertProgramming/blob/master/chapter09/9.1.2-timer_principle.md#%E5%81%9C%E6%AD%A2timer
Timer还未触发,系统协程已经删除该Timer,Stop()返回false; Timer已经触发,系统协程还未删除该Timer,Stop()返回true;
https://golang.google.cn/pkg/time/#Timer.Stop
It returns true if the call stops the timer, false if the timer has already expired or been stopped.
可能是这样的?
- Timer还未触发,且系统协程还未删除该Timer,Stop()返回true
- Timer已经触发,或系统协程已经删除该Timer,Stop()返回false
回头我看下,正准备结合1.14重新看下呢。谢谢
你说得对,不过,简单点怎么样?
- Timer还未触发,Stop()返回true
- Timer已经触发,Stop()返回false
嗯,主要是调用过Stop(),那么再次调用必然返回false,不过应该没人这么干。