Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "fmt"
- "sync"
- )
- func main() {
- var wg sync.WaitGroup
- var c = make(chan string)
- for i := 0; i <= 10; i++ {
- wg.Add(1)
- go func(i int) {
- c <- fmt.Sprintf("Event #%d", i)
- wg.Done()
- }(i)
- }
- // Close the channel when all goroutines are finished
- go func() {
- wg.Wait()
- close(c)
- }()
- for res := range c {
- fmt.Printf("Result: %s\n", res)
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement