Created
February 4, 2017 04:52
-
-
Save torufurukawa/e6158bb10ccc6b166a474ace273613e4 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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