Last active
January 24, 2019 13:38
-
-
Save catvec/ce0ef574a193435b466ae2caa30bb558 to your computer and use it in GitHub Desktop.
Go context.Done() question
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" | |
"time" | |
) | |
func main() { | |
ctx, ctxCancel := context.WithCancel(context.Background()) | |
go func() { | |
// PLACE 1 | |
<-ctx.Done() | |
}() | |
go func() { | |
time.Sleep(1000 * time.Millisecond) | |
ctxCancel() | |
}() | |
// PLACE 2 | |
<-ctx.Done() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment