Skip to content

Instantly share code, notes, and snippets.

@krishna2nd
Created October 25, 2017 01:32
Show Gist options
  • Select an option

  • Save krishna2nd/27fae7da220eae3491b74ebdfce286a3 to your computer and use it in GitHub Desktop.

Select an option

Save krishna2nd/27fae7da220eae3491b74ebdfce286a3 to your computer and use it in GitHub Desktop.
Go dual channels
package main
import (
"fmt"
)
func printch(ch1, ch2, q chan int) {
for {
select {
case x := <-ch1:
fmt.Print(x)
case y := <-ch2:
fmt.Print(y)
case <-q:
fmt.Println("quiting..")
return
}
fmt.Println()
}
}
func main() {
var ch1, ch2, q = make(chan int), make(chan int), make(chan int)
go func() {
for i := 0; i < 10; i++ {
ch2 <- i * i
ch1 <- i
}
q <- 0
}()
printch(ch1, ch2, q)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment