Skip to content

Instantly share code, notes, and snippets.

@jreisinger
Last active October 22, 2018 06:17
Show Gist options
  • Select an option

  • Save jreisinger/4ce0741d9aad2e07514d6549f2c2f89f to your computer and use it in GitHub Desktop.

Select an option

Save jreisinger/4ce0741d9aad2e07514d6549f2c2f89f to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"time"
)
func printer(msg string, stopCh chan bool) {
for {
select {
case <-stopCh:
return
default:
fmt.Printf("%s\n", msg)
}
}
}
func main() {
stopCh := make(chan bool)
for i := 0; i < 10; i++ {
go printer(fmt.Sprintf("printer: %d", i), stopCh)
}
time.Sleep(time.Second * 2)
close(stopCh)
time.Sleep(time.Second * 2)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment