Skip to content

Instantly share code, notes, and snippets.

@peteretelej
Created October 22, 2017 19:55
Show Gist options
  • Save peteretelej/39c4501e0cd0d5e9b2f82d3fb1d72244 to your computer and use it in GitHub Desktop.
Save peteretelej/39c4501e0cd0d5e9b2f82d3fb1d72244 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"log"
"sync"
"time"
)
func main() {
wg := &sync.WaitGroup{}
c := make(chan string)
wg.Add(10)
for i := 1; i <= 10; i++ {
go func(ind int, ch <-chan string) {
for v := range c {
time.Sleep(time.Millisecond)
log.Printf("Goroutine %d: %s", ind, v)
}
wg.Done()
}(i, c)
}
for i := 0; i < 20000; i++ {
c <- fmt.Sprintf("value %d", i)
}
close(c)
wg.Wait()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment