Introduction
In this challenge, you'll create a Go program that demonstrates the power of channels by building a simple data processing pipeline that transfers integers between goroutines. You'll need to create a buffered channel, write the numbers 1-5 into the channel, and then read and print each number from the channel in the order they were written.
Build a Simple Channel Data Pipeline
In this challenge, you'll create a Go program that demonstrates the power of channels by building a simple data processing pipeline that transfers integers between goroutines.
Tasks
- Create a buffered channel of integers with a capacity of 5
- Write the numbers 1, 2, 3, 4, and 5 into the channel
- Read and print each number from the channel in the order they were written
Requirements
- Use the file
~/project/data_pipeline.go - Create a buffered channel using
make(chan int, 5) - Use the channel send operator
<-to write numbers to the channel - Use the channel receive operator
<-to read numbers from the channel - Print each number using
fmt.Println() - Ensure all numbers are written and read completely
Examples
Run the program:
go run data_pipeline.go
Expected output:
1
2
3
4
5
Hints
- Remember to use
ch <- valueto send values to the channel - Use
value := <-chto receive values from the channel - Buffered channels allow sending multiple values before blocking
- Close the channel after writing all values if needed
Summary
In summary, this challenge requires you to create a Go program that uses channels to build a simple data processing pipeline. You'll need to create a buffered channel, write the numbers 1-5 into the channel, and then read and print each number from the channel in the order they were written.



