Go code
messages := make(chan string)
go func() { messages <- "done" }()
message := <-messages
fmt.Println(message)Line-by-line explanation
- Make creates a string channel.
- A goroutine sends done with the left-pointing arrow.
- Main receives from the channel.
- The message is displayed.
Expected output
doneThis is the expected result.
An unbuffered send waits until another goroutine is ready to receive. That waiting provides synchronization.