GoExpertProgramming icon indicating copy to clipboard operation
GoExpertProgramming copied to clipboard

timer.Stop() 返回值的解释貌似有误

Open marjune163 opened this issue 4 years ago • 3 comments

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

marjune163 avatar Mar 13 '20 03:03 marjune163

回头我看下,正准备结合1.14重新看下呢。谢谢

RainbowMango avatar Mar 15 '20 13:03 RainbowMango

你说得对,不过,简单点怎么样?

  • Timer还未触发,Stop()返回true
  • Timer已经触发,Stop()返回false

RainbowMango avatar Mar 31 '20 14:03 RainbowMango

嗯,主要是调用过Stop(),那么再次调用必然返回false,不过应该没人这么干。

marjune163 avatar Apr 01 '20 03:04 marjune163