Hi Jinsu,
Some real world example is when you create a function to download video from url, convert, and re upload the result. The stages could be breaking down into smaller task, eg:
- Download video from URL
- Resize the video into multiple resolution
- Upload it to S3
- Notify the user when video has been processed.
And each stage should be run on separated goroutine.
On the example above, the time.Sleep is used for simulating heavy process, and the heavy process run on separated goroutine. Since we use goroutine and channel, switching context occurred when we consume the data. Switching context it self not free (but it is cheap), but since you just removed the time.Sleep, switching context on goroutine itself it more costly compared to simple calculation on the above example.