Unbuffered channel - range , done and close

I was going through source code of Concurrency in Go by Katherine.

In this I found by editing, that done is not the one closing the intStream, addStream or others.

The intStream got closed on its own , once range of integers were iterated over.

What does it mean to have range over an unbuffered channel?
Until the unbuffered channel is closed, this will never be iterated completely?.

If that is the case - done here is never used at all. Because intStream is closing on its own?. I want someone to help in knowing if my understanding is right or not?



Why? Buffered/unbuffered is about capacity of channel and that important in meaning blocking/non-blocking operations.There is a great article - https://go101.org/article/channel.html.

Because the sample doesn’t cover example for case when process should stop processing before ending input data.
For example you have really huge amount of raw data, log operations or something. And you sift all these piace through pipe (transforming process) while the result will not have been found. And when you got it - just send something in ‘done’ channel and that stopped all pipe in whole. But the example not very accurate (or maybe I missing something) if message will retrieve in middle of pipe - that can lead to panic if previous chanel will sent data to closed channel (sometimes it’s totally ok - “let it die/crash” approach)

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.