Last active
October 22, 2018 06:17
-
-
Save jreisinger/4ce0741d9aad2e07514d6549f2c2f89f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| 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