LESSON · 1 OF 23

What is a channel

What is a channel

Goroutines run concurrently, but on their own they cannot share a result. A channel is the pipe that connects them: one goroutine sends a value in, another receives it out.

Channels are typed. A chan int carries only ints and a chan string carries only strings, so the value you receive is always the type you expect.

The channel does two jobs at once. It moves the data between goroutines, and it coordinates them, so you get a value across without writing any locks or shared variables. The next few nodes build up how you make one, send on it, and receive from it.

Spin up a fresh environment and practice live.
go · fresh machine · ready in under a minute