Currently when the writer calls close on a channel, if there are remaining values then those will be returned back to the writer and the channel will be closed immediately. Readers will not be able to read these remaining elements.
Another use case is that the writer should be able to signal that they are done writing and only when the reader reads the last remaining value should the channel then be closed.
It is quite tricky to do this with the current API. The writer has to only close if the channel is empty, otherwise set some other AtomicBoolean signal, and the reader has to handle both the channel being closed and this other signal.
@steinybot should the new method wait only for the channel's internal queue to be empty? What should the behavior be if there are pending takes or puts?
Currently when the writer calls
close
on a channel, if there are remaining values then those will be returned back to the writer and the channel will be closed immediately. Readers will not be able to read these remaining elements.Another use case is that the writer should be able to signal that they are done writing and only when the reader reads the last remaining value should the channel then be closed.
It is quite tricky to do this with the current API. The writer has to only close if the channel is empty, otherwise set some other
AtomicBoolean
signal, and the reader has to handle both the channel being closed and this other signal.