Channels

suggest change

Channels are typed queues that goroutines use to communicate in a thread-safe way.

The zero value of a channel is nil.

Channel basics

	// create an unbuffered channel of int values (capacity 0)
	ch := make(chan int)
	// start a new goroutine that sends value 3 over a channel
	go func() { ch <- 3 }()
	// read the value from a channel
	// it waits until goroutine above sends a value
	n := <-ch
	fmt.Printf("n: %d\n", n)
n: 3

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents