Last active
December 10, 2022 07:22
-
-
Save ehfeng/aca1c74502b801099ca0f7ba8f89b4cc 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
package main | |
import "fmt" | |
func f(x, y, z chan string) { | |
defer close(x) | |
a := make(chan bool) | |
go func() { | |
for i := 0; i < 3; i++ { | |
x <- "hi" | |
} | |
a <- true | |
}() | |
<-a | |
y <- "hello" | |
z <- "hola" | |
} | |
func main() { | |
x, y, z := make(chan string), make(chan string), make(chan string) | |
go f(x, y, z) | |
go func() { | |
for m := range x { | |
fmt.Println("m", m) | |
} | |
}() | |
select { | |
case b := <-y: | |
fmt.Println("b", b) | |
case c := <-z: | |
fmt.Println("c", c) | |
} | |
fmt.Println("end") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment