Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- func main() {}
- func Merge2Channels(f func(int) int, in1 <-chan int, in2 <-chan int, out chan<- int, n int) {
- go func() {
- ww1 := make(chan chan int, n)
- ww2 := make(chan chan int, n)
- go func() {
- for i := 0; i < n; i++ {
- f1 := <-<-ww1
- f2 := <-<-ww2
- out <- f1 + f2
- }
- }()
- input := func(in <-chan int, ww chan chan int) {
- for i := 0; i < n; i++ {
- w := make(chan int)
- ww <- w
- x := <-in
- go func(w chan int, x int) { w <- f(x) }(w, x)
- }
- }
- go input(in1, ww1)
- go input(in2, ww2)
- }()
- }
Add Comment
Please, Sign In to add comment