Skip to content

Instantly share code, notes, and snippets.

@taowen
Created March 2, 2018 02:01
Show Gist options
  • Save taowen/1689353c83c7cf3166ca6d7c63e4ca68 to your computer and use it in GitHub Desktop.
Save taowen/1689353c83c7cf3166ca6d7c63e4ca68 to your computer and use it in GitHub Desktop.
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