Skip to content

Instantly share code, notes, and snippets.

@catvec
Last active January 24, 2019 13:38
Show Gist options
  • Save catvec/ce0ef574a193435b466ae2caa30bb558 to your computer and use it in GitHub Desktop.
Save catvec/ce0ef574a193435b466ae2caa30bb558 to your computer and use it in GitHub Desktop.
Go context.Done() question
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