Break The Golang Context Chain
And enabling a context to be used after cancellation
Recently, I recalled a useful pattern that’s cropped up a few times at work. API handlers (think http.Handler), include a context.Context tied to the connectivity of the caller. If the client disconnects, the context closes, signaling to the handler that it can fail early and clean itself up. Importantly, the handler function returning also cancels the context. But what if you want to do an out-of-band operation after the request is complete?