Created
February 4, 2013 20:32
-
-
Save ecylmz/4709510 to your computer and use it in GitHub Desktop.
This file contains 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" | |
"time" | |
) | |
func main() { | |
c1 := make(chan string) | |
c2 := make(chan string) | |
go func() { | |
for { | |
c1 <- "from 1" | |
time.Sleep(time.Second * 2) | |
} | |
}() | |
go func() { | |
for { | |
c2 <- "from 2" | |
time.Sleep(time.Second * 3) | |
} | |
}() | |
go func() { | |
for { | |
select { | |
case msg1 := <- c1: | |
fmt.Println(msg1) | |
case msg2 := <- c2: | |
fmt.Println(msg2) | |
} | |
} | |
}() | |
var input string | |
fmt.Scanln(&input) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment