

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 4
click for more info
Not enough gems
Cost: 6 gems
1: Concurrency
incomplete
2: Channels
incomplete
3: Channels
incomplete
4: Buffered Channels
incomplete
5: Closing Channels in Go
incomplete
6: Range
incomplete
7: Select
incomplete
8: Select Default Case
incomplete
9: Channels Review
incomplete
10: Ping Pong
incomplete
Back
ctrl+,
Next
ctrl+.
This lesson's interactive features are locked, please to keep using them
Channels can optionally be buffered.
You can provide a buffer length as the second argument to make() to create a buffered channel:
ch := make(chan int, 100)
A buffer allows the channel to hold a fixed number of values before sending blocks. This means sending on a buffered channel only blocks when the buffer is full, and receiving blocks only when the buffer is empty.
We want to be able to send emails in batches. A writing goroutine will write an entire batch of email messages to a buffered channel, and later, once the channel is full, a reading goroutine will read all of the messages from the channel and send them out to our clients.
Complete the addEmailsToQueue function. It should create a buffered channel with a buffer large enough to store all of the emails it's given. It should then write the emails to the channelĀ in order, and finally return the channel.