3 ms·
It is about immutability, at least in the visible API. The stdlib context functions all only expose the `context.Context` interface which has no methods to muta
by morelisp 6y ago
It is about immutability, at least in the visible API. The stdlib context functions all only expose the `context.Context` interface which has no methods to mutate it. Any "changes" to a context can only be done by making a child context, which also ensures the caller's desired deadline/timeout semantics are enforced as each layer can only add cancellation conditions; similarly you cannot remove values, only replace them.
(Though internally there are some nasty optimizations to chain cancellation with minimal channel waits.)