summaryrefslogtreecommitdiff
path: root/api
diff options
context:
space:
mode:
authorSameer Ajmani <sameer@golang.org>2022-01-06 13:57:05 -0500
committerGopher Robot <gobot@golang.org>2022-11-08 13:51:16 +0000
commit5b42f89e394a9e9fbd28fa93cc8a09186db0f233 (patch)
tree5c54ffff91741333a20485a6461e71e5082619da /api
parent0b7aa9fa5b207a3d9e2b1de2629babb6f5ce6e45 (diff)
downloadgo-git-5b42f89e394a9e9fbd28fa93cc8a09186db0f233.tar.gz
context: add APIs for writing and reading cancelation cause
Extend the context package to allow users to specify why a context was canceled in the form of an error, the "cause". Users write the cause by calling WithCancelCause to construct a derived context, then calling cancel(cause) to cancel the context with the provided cause. Users retrieve the cause by calling context.Cause(ctx), which returns the cause of the first cancelation for ctx or any of its parents. The cause is implemented as a field of cancelCtx, since only cancelCtx can be canceled. Calling cancel copies the cause to all derived (child) cancelCtxs. Calling Cause(ctx) finds the nearest parent cancelCtx by looking up the context value keyed by cancelCtxKey. API changes: +pkg context, func Cause(Context) error +pkg context, func WithCancelCause(Context) (Context, CancelCauseFunc) +pkg context, type CancelCauseFunc func(error) Fixes #26356 Fixes #51365 Change-Id: I15b62bd454c014db3f4f1498b35204451509e641 Reviewed-on: https://go-review.googlesource.com/c/go/+/375977 Reviewed-by: Damien Neil <dneil@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Sameer Ajmani <sameer@golang.org> Auto-Submit: Sameer Ajmani <sameer@golang.org>
Diffstat (limited to 'api')
-rw-r--r--api/next/51365.txt3
1 files changed, 3 insertions, 0 deletions
diff --git a/api/next/51365.txt b/api/next/51365.txt
new file mode 100644
index 0000000000..df629f1852
--- /dev/null
+++ b/api/next/51365.txt
@@ -0,0 +1,3 @@
+pkg context, func Cause(Context) error #51365
+pkg context, func WithCancelCause(Context) (Context, CancelCauseFunc) #51365
+pkg context, type CancelCauseFunc func(error) #51365