1
0
mirror of https://github.com/golang/go synced 2024-11-24 01:30:10 -07:00
go/api/next
Sameer Ajmani 5b42f89e39 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>
2022-11-08 13:51:16 +00:00
..
31804.txt crypto/ed25519: implement Ed25519ph in Sign and VerifyWithOptions 2022-10-24 12:11:20 +00:00
41773.txt net/http: add Server.DisableOptionsHandler for custom handling of OPTIONS * 2022-08-15 18:57:35 +00:00
42537.txt cmd/api: make check pickier about api/*.txt 2022-11-02 19:08:10 +00:00
43620.txt cmd/api: make check pickier about api/*.txt 2022-11-02 19:08:10 +00:00
45038.txt bytes: add Clone function 2022-08-15 19:17:20 +00:00
45899.txt cmd/api: make check pickier about api/*.txt 2022-11-02 19:08:10 +00:00
46731.txt cmd/cgo: add and use runtime/cgo.Incomplete instead of //go:notinheap 2022-08-28 16:04:49 +00:00
46746.txt cmd/api: make check pickier about api/*.txt 2022-11-02 19:08:10 +00:00
47209.txt path/filepath, io/fs: add SkipAll 2022-08-25 18:50:37 +00:00
48000.txt reflect: add Value.Grow 2022-10-15 17:02:11 +00:00
50429.txt cmd/api: make check pickier about api/*.txt 2022-11-02 19:08:10 +00:00
50436.txt os/exec: add the Cancel and WaitDelay fields 2022-10-25 03:34:36 +00:00
50770.txt time: implement Compare method 2022-09-19 17:10:49 +00:00
51246.txt syscall: add CgroupFD support for ForkExec on Linux 2022-09-09 15:34:16 +00:00
51365.txt context: add APIs for writing and reading cancelation cause 2022-11-08 13:51:16 +00:00
51430.txt runtime/coverage: revise/shorten function names 2022-10-05 14:59:05 +00:00
51668.txt
51766.txt net/netip: add IPv6LinkLocalAllRouters and IPv6Loopback 2022-10-21 20:14:41 +00:00
51777.txt net/netip: add IPv6LinkLocalAllRouters and IPv6Loopback 2022-10-21 20:14:41 +00:00
51896.txt cmd/api: make check pickier about api/*.txt 2022-11-02 19:08:10 +00:00
52221.txt crypto/ecdh: new package 2022-08-12 00:03:39 +00:00
52376.txt reflect: add Value.SetZero 2022-08-26 17:15:08 +00:00
52746.txt
53002.txt net/http/httputil: add ReverseProxy.Rewrite 2022-08-16 20:01:36 +00:00
53021.txt crypto/subtle: add XORBytes 2022-08-17 18:47:33 +00:00
53200.txt go/token: add (*FileSet).RemoveFile(*File) method 2022-08-16 16:27:35 +00:00
53202.txt go/ast: record start and end of file in File.File{Start,End} 2022-09-28 20:37:59 +00:00
53280.txt syscall: remove FreeBSD 11 and below 64bit inode compatibility shims 2022-09-16 01:17:28 +00:00
53346.txt encoding/xml: add (*Encoder).Close 2022-08-23 18:24:30 +00:00
53356.txt debug/elf: fix reloc number of R_PPC64_SECTOFF_LO_DS 2022-08-27 02:36:28 +00:00
53435.txt errors, fmt: add support for wrapping multiple errors 2022-09-29 18:40:40 +00:00
53482.txt cmd/api: make check pickier about api/*.txt 2022-11-02 19:08:10 +00:00
54222.txt
54251.txt
54345.txt debug/elf: fix typo in R_PPC64_TPREL34 and R_PPC64_DTPREL34 2022-09-29 19:54:44 +00:00
55301.txt api: add newline to 55301.txt 2022-11-04 14:19:00 +00:00
56041.txt regexp: add ErrLarge error 2022-11-02 18:15:21 +00:00