Skip to content

Instantly share code, notes, and snippets.

@g14a
Last active October 10, 2018 14:55
Show Gist options
  • Save g14a/ed63402a9282a595986e9b406dad95cb to your computer and use it in GitHub Desktop.
Save g14a/ed63402a9282a595986e9b406dad95cb to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"sync"
)
func main() {
ch := make(chan int)
var wg sync.WaitGroup
for i := 0; i < 10; i++ {
wg.Add(1)
go func(k int, wg *sync.WaitGroup) {
defer wg.Done()
ch <- k
}(i, &wg)
}
for {
i, more := <-ch
if more {
fmt.Println(i)
} else {
fmt.Println()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment