Re: [go-nuts] cancel method of timerCtx of context package

2021-05-19 Thread Ian Lance Taylor
On Wed, May 12, 2021 at 6:43 PM qinggeer Bao  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.


[go-nuts] cancel method of timerCtx of context package

2021-05-12 Thread qinggeer Bao
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? 

-- 
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/b6ec3bd3-4f4e-4a8d-a43f-3a185b5f1ac9n%40googlegroups.com.