It’s pretty cool. Context cancellation is such an odd thing and so often mishandled. I’m glad this exists but I also feel some ennui about the context package as a whole.
In the very early days of Go an engineer at Google Sydney told me very directly that we needed to think about timeouts and cancellation *now* and I didn’t take him seriously enough. I think it could have been part of the language, and been easier to manage correctly.
Although I’m not sure what that would look like and now that I’m so closely acquainted with the status quo it’s hard for me to imagine it any other way.
Nono it's not for business logic, the magic is that it allows turning non-Context APIs into Context APIs: as long as there is some way to cancel an operation (e.g. calling Close), you put it in an AfterFunc, and just like that you have a Context API.
Honestly I have that more and more since the language is evolving. So many new additions to the language. Go is losing it's "Go is simple" (simple as in a manageable API surface ) adage
Eh, I hear that all the time and it sounds a bit like any other "things used to be better." I don't see how a Go with Context.AfterFunc is even marginally harder to manage than a Go without. You can just not use it.
I explicitly mentioned what I meant with simple, omitting that feels like you're trying to ridicule something you don't agree with.
I was merely observing a community arguing for months for a math.Round() function and now it flipped on to the other end: "syntactic sugar for everything".
Context.AfterFunc is definitely not syntactic sugar?
I think this is not productive, so I'll step back.
I stand by my not seeing how any of this is counter-proof of “Go is simple” (simple as in a manageable API surface), parenthetical which I omitted because I was from mobile.
Comments
IDK, but these are the things I try to avoid like the plague.
I looked at the examples. If you use it to "defer" closing things it could be ok.
I'm also projecting what I know I'm going to see in a code review one day. 😂
The proof is in your own amazement of its existence, and you work on the language.
Simple is not measured in number of APIs.
I was merely observing a community arguing for months for a math.Round() function and now it flipped on to the other end: "syntactic sugar for everything".
I think this is not productive, so I'll step back.
I stand by my not seeing how any of this is counter-proof of “Go is simple” (simple as in a manageable API surface), parenthetical which I omitted because I was from mobile.