Last active
February 20, 2023 20:19
-
-
Save marvinhosea/625001d267eeadc1cc60872aceccdc51 to your computer and use it in GitHub Desktop.
Child context.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) | |
childCancelWithCause(errors.New("error: child canceled with cause")) | |
parentCancelWithCause(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