Skip to content

Instantly share code, notes, and snippets.

@marvinhosea
Last active February 20, 2023 20:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marvinhosea/dadae464577fd31d13d3f7634eb1a4aa to your computer and use it in GitHub Desktop.
Save marvinhosea/dadae464577fd31d13d3f7634eb1a4aa to your computer and use it in GitHub Desktop.
Cause
package main
import (
"context"
"errors"
"log"
)
func main() {
ctx, cancelWithCause := context.WithCancelCause(context.Background())
cancelWithCause(errors.New("error: cancellation cause"))
<-ctx.Done()
log.Println(ctx.Err())
log.Println(context.Cause(ctx))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment