Skip to content

Instantly share code, notes, and snippets.

@taowen
Created March 2, 2018 02:11
Show Gist options
  • Save taowen/a6941dc4b69559bf18ee010bfbce3d09 to your computer and use it in GitHub Desktop.
Save taowen/a6941dc4b69559bf18ee010bfbce3d09 to your computer and use it in GitHub Desktop.
// set a logger to show who is blocking
concurrent.InfoLogger = log.New(os.Stdout, "", 0)
executor := concurrent.NewUnboundedExecutor()
executor.Go(func(ctx context.Context) {
everyMillisecond := time.NewTicker(time.Millisecond)
for {
select {
case <-ctx.Done():
// info log will be printed while we wait
time.Sleep(time.Second)
fmt.Println("goroutine exited")
return
case <-everyMillisecond.C:
// do something
}
}
})
time.Sleep(time.Second)
executor.StopAndWaitForever()
fmt.Println("executor stopped")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment