News for hackers. Stuff that matters.
Re:Down the Golang Nil Rabbit Hole by kortex on Tuesday March 30, 2021 @08:42AM (#26633897)
But how do you cancel something without a handle to that something?

What (I think) you are suggesting implies globally scoped, mutable variables that affect control flow dramatically. Sounds really hard to reason about and very munch anti-Go-explicitness. Context is the handle by which an outer context holds on to the nested ones.

The only non-bonkers way to have a handle like that would be to give every function a getContext function to query some kind of context tree and signal parent/children. This is totally against Go explicitness as well.

Maybe something like Scala's implicits to sugar it, but that's another not-go-looking pattern (although it would be nice)

Re:Down the Golang Nil Rabbit Hole by bbatha on Tuesday March 30, 2021 @09:10AM (#26634148)
The go statement could return a handle to the go routine. There can be a cancel magic function that cancels the go routine. You can regain the task local storage by using this handle as a key into a map of task data. This would have been a breaking change particularly in CGo threads but it’s a vastly simpler model for the user.
Re:Down the Golang Nil Rabbit Hole by saturn_vk on Tuesday March 30, 2021 @03:31PM (#26639242)
This is just hypothetical, but the go statement could be an expression that returns a cancel function. From there, the sky is the limit. And in the other side, have a runtime.Done function that returns a channel that will need closed when the said cancel function is called. There are a bunch of other runtime functions that are goroutine specific already, so there is precedent