Subscribed unsubscribe Subscribe Subscribe

OngaLog

最近GOが楽しくて、

Go Channels サンプル

The Go Playground

package main
import "fmt"

func main() {
  
    messages1 := make(chan string)
    messages2 := make(chan string)
    messages3 := make(chan string)  
    
    go func() { messages1 <- "ping1" }()
    go func() { messages2 <- "ping2" }()
    go func() { messages3 <- "ping3" }()

    msg1 ,msg2, msg3 := <-messages1 , <-messages2 , <-messages3
    
    fmt.Println(msg1)
    fmt.Println(msg2)       
    fmt.Println(msg3)
}
ping1
ping2
ping3

参考サイト Go by Example: Channels