Created
March 2, 2018 02:01
-
-
Save taowen/1689353c83c7cf3166ca6d7c63e4ca68 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
import "github.com/modern-go/concurrent" | |
executor := concurrent.NewUnboundedExecutor() | |
executor.Go(func(ctx context.Context) { | |
everyMillisecond := time.NewTicker(time.Millisecond) | |
for { | |
select { | |
case <-ctx.Done(): | |
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