Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "math/rand"
- "time"
- )
- func Sender(intChannel chan <- int , stringChannel chan <- string, end chan <- bool) {
- randInt := rand.Int()
- if randInt%2 == 0 {
- intChannel <- randInt
- } else {
- stringChannel <- "odd"
- }
- end <- true
- }
- func Receiver(intChannel <- chan int , stringChannel <- chan string, end chan <- bool) {
- select {
- case val:= <-intChannel :
- println("Received ",val)
- case val := <-stringChannel :
- println("Received ",val)
- }
- end <- true
- }
- func main() {
- rand.Seed(time.Now().UTC().UnixNano())
- intChannel, stringChannel, end := make(chan int), make(chan string), make(chan bool)
- go Sender(intChannel,stringChannel,end)
- go Receiver(intChannel,stringChannel,end)
- <-end
- <-end
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement