On Wed, Nov 2, 2016, at 12:56 PM, 'Axel Wagner' via golang-nuts wrote:
> AIUI: A child or grandchild function is not supposed to signal that.
> They can return an error and let the parent cancel, or they can create
> their own child context WithCancel and cancel that. Context doesn't
> replace exceptions.

OK I see that. I think I don't understand the purpose of the Err method
if the function that creates the context is the one that cancels it or
closes the Done channel. It seems that the only purpose would be to
detect a Timeout.


> You should consider context a way to implement dynamic scoping[1]. A
> context is a thing valid for the current stack frame and downwards and
> should never affect the stack upwards. Which is also why there's the
> "put values in there, not pointers" rule; if you have a pointer, it
> might modify an upstack context.
>
> The advantage of that (and context in general) is, that you don't need
> to worry too much about synchronization and everything; as a context
> is fundamentally immutable (-ish), it's fine to pass it to separate
> goroutines, because they can only do stuff with it downstack.

Yes, this is what I am trying to do. I was wondering whether the
returned cancelFunc is something that could be passed downstream to
signal parents that work should be aborted.

Links:

  1. https://en.wikipedia.org/wiki/Scope_(computer_science)#Dynamic_scoping

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

Reply via email to