Context.TODO and Background have different String values; see emptyCtx.String. On Fri, Nov 17, 2017 at 9:25 PM me via golang-nuts < golang-nuts@googlegroups.com> wrote:
> I've found a hint. Apparently, both context.TODO and context.Background > share a common implementation but they need distinct addresses. > > See https://golang.org/src/context/context.go#L168 > > So they cannot be constants because then they would not have an address. > They cannot be variables because then you could modify them. Therefore the > only solution left is to make them a function that returns a variable. > > Then again, maybe you could make Background and TODO of an unexported type > to prevent setting them. I think that was not chosen because it leaks the > internals of the package. > > But I'm not sure why they need distinct addresses in the first place. I'm > guessing its for debugging or just what makes sense? context.TODO and > context.Background are two different contexts and should be treated as such. > > > On Friday, November 17, 2017 at 10:43:29 AM UTC-5, Alex Buchanan wrote: >> >> I don't have numbers, but context must be one of the most commonly used >> imports/types in my code. It shows up many function signatures. We try to >> use it for all cancelation. >> >> Would it make sense to add an alias "C" to the type "Context"? And maybe >> "BG" for Background()? >> >> Also, is there a specific reason Background is a function and not a value? >> >> Cheers, >> Alex >> > -- > 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. > -- 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.