Skip to content

Instantly share code, notes, and snippets.

@YassineBajdou
Created August 30, 2018 16:49
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 YassineBajdou/dbb94067acf8f6b8af2b9469f7a1343e to your computer and use it in GitHub Desktop.
Save YassineBajdou/dbb94067acf8f6b8af2b9469f7a1343e to your computer and use it in GitHub Desktop.
goroutines
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