Skip to content

Instantly share code, notes, and snippets.

@supershabam
Last active August 29, 2015 14:16
Show Gist options
  • Save supershabam/2156fedc58029e87d0a6 to your computer and use it in GitHub Desktop.
Save supershabam/2156fedc58029e87d0a6 to your computer and use it in GitHub Desktop.
go generate pipeliner example
//go:generate pipeliner map(func(string) string) concurrently as concMap into conc_map.go
func concMap(concurrency int, fn func(string) string, in <-chan string) <-chan string {
out := make(chan string)
go func() {
defer close(out)
wg := sync.WaitGroup{}
wg.Add(concurrency)
for i := 0; i < concurrency; i++ {
go func() {
defer wg.Done()
for item := range in {
out <- fn(item)
}
}()
}
wg.Wait()
}()
return out
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment