Skip to content

Instantly share code, notes, and snippets.

@ehfeng
Last active December 10, 2022 07:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ehfeng/aca1c74502b801099ca0f7ba8f89b4cc to your computer and use it in GitHub Desktop.
Save ehfeng/aca1c74502b801099ca0f7ba8f89b4cc to your computer and use it in GitHub Desktop.
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