Created
January 15, 2018 05:16
-
-
Save campoy/28014178f1de6c65acfc3806d25fc728 to your computer and use it in GitHub Desktop.
This file contains 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
func merge(a, b <-chan int) <-chan int { | |
c := make(chan int) | |
go func() { | |
defer close(c) | |
for a != nil || b != nil { | |
select { | |
case v, ok := <-a: | |
if !ok { | |
fmt.Println("a is done") | |
a = nil | |
continue | |
} | |
c <- v | |
case v, ok := <-b: | |
if !ok { | |
fmt.Println("b is done") | |
b = nil | |
continue | |
} | |
c <- v | |
} | |
} | |
}() | |
return c | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment