Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
context: Context.Done() is misleading, Cancelled() should be used instead #33523
While learning Go I started working working with contexts I've found that the naming of the function that returns a Channel signaling if a context has been cancelled is misleading.
Take the following example:
Now have a look at this alternative, where I have replaced the Done() with Cancelled()
I personally find the second version a lot more clear about what is going on as I no longer have to make the logic leap that when a context is "cancelled" that results in the channel that is returned via the to a function call of Done().
While it makes sense in the context of a context, as the context has been cancelled it's work has been done. This however is not as clear to people who have never used contexts before thus increasing their barrier of entry to the package (and ultimately the language as well)
Note that a context can also be "Done" if it times out, if it was created using
That said, you may well be right that
I would agree with what you saying, however a large amount documentation and existing guides I've encountered all talk about
Edit: Could please explain you can't see a reasonable way to change it when surely all that would be needed would be to rename Done() to Cancelled() and then re-create Done() as wrapper to Cancelled() which is deprecated?