-
-
Save RavenZZ/3cadb928c0f684a2794e4ac0766bf44a 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