mirror of
https://github.com/golang/go
synced 2024-11-24 02:30:12 -07:00
5b42f89e39
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> |
||
---|---|---|
.. | ||
31804.txt | ||
41773.txt | ||
42537.txt | ||
43620.txt | ||
45038.txt | ||
45899.txt | ||
46731.txt | ||
46746.txt | ||
47209.txt | ||
48000.txt | ||
50429.txt | ||
50436.txt | ||
50770.txt | ||
51246.txt | ||
51365.txt | ||
51430.txt | ||
51668.txt | ||
51766.txt | ||
51777.txt | ||
51896.txt | ||
52221.txt | ||
52376.txt | ||
52746.txt | ||
53002.txt | ||
53021.txt | ||
53200.txt | ||
53202.txt | ||
53280.txt | ||
53346.txt | ||
53356.txt | ||
53435.txt | ||
53482.txt | ||
54222.txt | ||
54251.txt | ||
54345.txt | ||
55301.txt | ||
56041.txt |