Skip to content

Instantly share code, notes, and snippets.

@iamspark1e
Created September 19, 2022 06:52
Show Gist options
  • Select an option

  • Save iamspark1e/8ced2feedca60e58e49e4267973d7c93 to your computer and use it in GitHub Desktop.

Select an option

Save iamspark1e/8ced2feedca60e58e49e4267973d7c93 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"runtime"
"time"
)
func main() {
ticker := time.NewTicker(200 * time.Millisecond)
done := make(chan bool)
go func() {
for {
select {
case <-done:
return
case t := <-ticker.C:
fmt.Println("Tick at", t)
}
}
// runtime.Goexit()
}()
time.AfterFunc(time.Second, func() {
fmt.Println("run ticker.Stop() at " + time.Now().String())
ticker.Stop()
done <- true
})
time.Sleep(2 * time.Second)
fmt.Println(runtime.NumGoroutine())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment