Created
March 2, 2018 02:11
-
-
Save taowen/a6941dc4b69559bf18ee010bfbce3d09 to your computer and use it in GitHub Desktop.
This file contains 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
// 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