Skip to content

Instantly share code, notes, and snippets.

@torufurukawa
Created February 4, 2017 04:52
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 torufurukawa/e6158bb10ccc6b166a474ace273613e4 to your computer and use it in GitHub Desktop.
Save torufurukawa/e6158bb10ccc6b166a474ace273613e4 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
)
func main() {
in1 := make(chan int)
in2 := make(chan string)
done := make(chan bool)
go loop(in1, in2, done)
in1 <- 0
in2 <- "hello"
in1 <- 1
in2 <- "bye"
in1 <- 999
<-done
}
func loop(in1 chan int, in2 chan string, done chan bool) {
fmt.Println("STARTED")
for {
//fmt.Println("LOOP")
select {
case num, ok := <- in1 :
if !ok {
fmt.Println("ERROR", ok)
break
}
fmt.Println("NUMBER", num)
if num == 999 {
fmt.Println("FINISHED")
done <-true
return
}
case str, _ := <- in2:
fmt.Println("STRING", str)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment