Skip to content

Instantly share code, notes, and snippets.

@jreisinger
Last active October 16, 2018 10:52
Show Gist options
  • Select an option

  • Save jreisinger/84ca999d6a0a2531c34b28e2a0f14141 to your computer and use it in GitHub Desktop.

Select an option

Save jreisinger/84ca999d6a0a2531c34b28e2a0f14141 to your computer and use it in GitHub Desktop.
// There's no "channel broadcast" in Go, i.e. you can't send something to multiple goroutines using the same channel. However you can close the channel and all goroutines will be notified.
package main
import (
"fmt"
"time"
)
func printer(msg string, goCh chan bool) {
<-goCh
fmt.Printf("%s\n", msg)
}
func main() {
goCh := make(chan bool)
for i := 0; i < 10; i++ {
go printer(fmt.Sprintf("printer: %d", i), goCh)
}
time.Sleep(time.Second * 2)
close(goCh)
time.Sleep(time.Second * 2)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment