Channels


Either the sender or the receiver will be blocked till the other side is also ready. Only when they are aligned the message will be sent and then both will continue running.

examples/channels/channels.go
package main

import (
    "fmt"
)

func main() {
    fmt.Println("Start")
    c := make(chan string)

    go sendMessage(c)

    msg := <-c
    fmt.Println(msg)

    fmt.Println("End")
}

func sendMessage(c chan string) {
    c <- "Hello World"
}

Start
Hello World
End