Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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.

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