Skip to content

Instantly share code, notes, and snippets.

@campoy
Last active December 24, 2018 06:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save campoy/b3f33358934e960ab9de3d3d435a048f to your computer and use it in GitHub Desktop.
Save campoy/b3f33358934e960ab9de3d3d435a048f to your computer and use it in GitHub Desktop.
func merge(cs ...<-chan int) <-chan int {
out := make(chan int)
var wg sync.WaitGroup
wg.Add(len(cs))
for _, c := range cs {
go func(c <-chan int) {
for v := range c {
out <- v
}
wg.Done()
}(c)
}
go func() {
wg.Wait()
close(out)
}()
return out
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment