FAQ
I am reviewing the context.go code, it's very cool, but I have a question
on the goroutine in func propagateCancel(), the red part below, my
understand is if this part get the change to run, that mean parentCancelCtx(parent)
should return false, that said we can't find a canceled parent in the tree,
this also mean parent.Done() should be nil, so this func should be return
in line#228, so the goroutine with red part will never get the chance to
run, was my understand right? thanks!

225 // propagateCancel arranges for child to be canceled when parent is.
226 func propagateCancel(parent Context, child canceler) {
227 if parent.Done() == nil {
228 return // parent is never canceled
229 }
230 if p, ok := parentCancelCtx(parent); ok {
231 p.mu.Lock()
232 if p.err != nil {
233 // parent has already been canceled
234 child.cancel(false, p.err)
235 } else {
236 if p.children == nil {
237 p.children = make(map[canceler]bool)
238 }
239 p.children[child] = true
240 }
241 p.mu.Unlock()
242 } else {
243 go func() {
244 select {
245 case <-parent.Done():
246 child.cancel(false, parent.Err())
247 case <-child.Done():
248 }
249 }()
250 }
251 }

--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedDec 16, '15 at 2:30a
activeDec 16, '15 at 2:30a
posts1
users1
websitegolang.org

1 user in discussion

Zoutaiqi: 1 post

People

Translate

site design / logo © 2022 Grokbase