Goroutines and Channels
Part of the Go course
Your program needs to download twenty files. Written the ordinary way, it downloads the first one, waits, downloads the second one, waits, and so on. Almost all of that time is spent doing nothing at all, just waiting for a network that is slower than your processor by a factor of millions. The work would finish twenty times sooner if the waiting overlapped.
Doing several things at once is the oldest hard problem in programming, and most languages make it genuinely difficult. Go was designed around it, and this is the lesson where that shows. You get two ideas. A goroutine is a piece of your program that runs alongside the rest of it. A channel is a pipe for handing values from one goroutine to another, safely, without you having to arrange any locking.
Want to learn Go Goroutines and Channels in a real environment?
Click below, get a fresh Linux box with Go ready to go, and work through Goroutines and Channels hands-on with an AI tutor that knows your code.
Start this lessonGoroutines and ChannelsWhat you'll learn
- The go keyword
- Goroutine lifetime
- Unbuffered channels
- Buffered channels
- Send and receive
- Range over channel
- Close a channel
