Last active
August 29, 2015 14:16
-
-
Save supershabam/2156fedc58029e87d0a6 to your computer and use it in GitHub Desktop.
go generate pipeliner example
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
//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