Created
October 22, 2017 19:55
-
-
Save peteretelej/39c4501e0cd0d5e9b2f82d3fb1d72244 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" | |
"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