Standard library / context
context.CancelCauseFunc
Cancellation function that records an error. A nil cause becomes Canceled. The first cancellation wins. Expected stdout: 'true\n'.
Formal Syntax & Structure
go syntaxgo
type CancelCauseFunc func(cause error)Working Example
Example Snippetgo
package main
import ( "context" "fmt")
func main() { ctx, cancel := context.WithCancelCause(context.Background()) var f context.CancelCauseFunc = cancel f(nil) fmt.Println(context.Cause(ctx) == context.Canceled)}