

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
Similar to slices and maps, channels can be ranged over.
for item := range ch {
// item is the next value received from the channel
}
This example will receive values over the channel (blocking at each iteration if nothing new is there) and will exit only when the channel is closed.
It's that time again, Textio is hiring and we've been assigned to do the interview. The Fibonacci sequence is Textio's interview problem of choice. We've been tasked with building a small toy program we can use in the interview.
Complete the concurrentFib function. It should:
The fibonacci function is the producer: it runs in its own goroutine and sends numbers into the channel. The concurrentFib function is the consumer: it reads all the numbers from that channel using a range loop and aggregates them.