Go: why context.TODO() and not context.Background()?

Hi @dalu,

As you mentioned in your response, they are the same context (no timeout/deadline and no associated values). The difference is semantic. I think of context.Background as “I’m deliberately passing in an empty context” and context.TODO as “there should be some other context here, which could be empty, but I’m not sure what the right value is yet so here’s a placeholder”.

We use context.TODO() in the examples embedded in our documentation because the correct value would depend on the calling function, which is usually code from the user’s application. In this case, it’s up to the user to decide what the context should be, which usually depends on things like the maximum time they want the operation to take and whether or not the calling function has a context that it can propagate.

– Divjot

4 Likes