Created
February 20, 2023 10:35
-
-
Save marvinhosea/bc0c47869a6af22afb52e339c2588644 to your computer and use it in GitHub Desktop.
Contexpareet.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"context" | |
"errors" | |
"log" | |
) | |
func main() { | |
parentCtx, parentCancelWithCause := context.WithCancelCause(context.Background()) | |
childCtx, childCancelWithCause := context.WithCancelCause(parentCtx) | |
parentCancelWithCause(errors.New("error: parent canceled with cause")) | |
childCancelWithCause(nil) | |
<-parentCtx.Done() | |
<-childCtx.Done() | |
log.Println(parentCtx.Err()) | |
log.Println(childCtx.Err()) | |
log.Println(context.Cause(parentCtx)) | |
log.Println(context.Cause(childCtx)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment