On Wed, May 12, 2021 at 6:43 PM qinggeer Bao <baoq...@gmail.com> wrote:
>
> In the cancel method of timerCtx type:
>
> func (c *timerCtx) cancel(removeFromParent bool, err error) {
>     c.cancelCtx.cancel(false, err)
>     if removeFromParent {
>         // Remove this timerCtx from its parent cancelCtx's children.
>         removeChild(c.cancelCtx.Context, c)
>     }
>     c.mu.Lock()
>     if c.timer != nil {
>         c.timer.Stop()
>         c.timer = nil
>     }
>     c.mu.Unlock()
> }
>
> why it use the following:
>     c.cancelCtx.cancel(false, err)
>     if removeFromParent {
>         // Remove this timerCtx from its parent cancelCtx's children.
>         removeChild(c.cancelCtx.Context, c)
>     }
>
> instead, direclty call
> c.cancelCtx.cancel(removeFromParent, err)
>
> Is there any reason?

The two calls look the same but they are not the same.  The c passed
to removeChild by cancelCtx.cancel is not the same as the c passed to
removeChild by timerCtx.cancel.

Ian

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcVKZ4H4Hm%2B-qe85GLa8yA%2BO6vV%3DGdSb7Pc3ovVTze8quA%40mail.gmail.com.

Reply via email to