Created
August 30, 2018 16:49
-
-
Save YassineBajdou/dbb94067acf8f6b8af2b9469f7a1343e to your computer and use it in GitHub Desktop.
goroutines
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
func main() { | |
c1 := make(chan string) | |
c2 := make(chan string) | |
go func() { | |
for { | |
c1 <- "hello from channel 1" | |
} | |
}() | |
go func() { | |
for { | |
c2 <- "hello from channel 2" | |
} | |
}() | |
go func() { | |
for { | |
select { | |
case msg1 := <- c1: | |
fmt.Println(mg1) | |
case msg2 := <- c2: | |
fmt.Println(mg2) | |
default: | |
fmt.Println("Nothing is ready yet.") | |
} | |
} | |
}() | |
var input string | |
fmt.Scanln(&input) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment