Skip to content

Instantly share code, notes, and snippets.

@kogai
Created January 25, 2018 07:55
Show Gist options
  • Select an option

  • Save kogai/f07be483b293e7cda55e875b634c5bd1 to your computer and use it in GitHub Desktop.

Select an option

Save kogai/f07be483b293e7cda55e875b634c5bd1 to your computer and use it in GitHub Desktop.
package main
import ("time")
func Producer(ch chan int) {
for i := 0; i < 5; i++ { ch <- i }
println("close")
close(ch)
}
func Consumer(ch1, _ chan int) {
for {
select {
case x := <- ch1: {
if x > 0 {
println("ch1-", x)
}
}
// case x := <- ch2: println("ch2-", x)
}
}
}
func main() {
ch1, ch2 := make(chan int), make(chan int)
go Producer(ch1)
// go Producer(ch2)
// Consumer(ch1, ch2)
for {
select {
case x := <- ch1: {
if x > 0 {
println("ch1-", x)
}
}
// case x := <- ch2: println("ch2-", x)
}
}
time.Sleep(time.Second * 5)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment