getkyo / kyo

Toolkit for Scala Development
https://getkyo.io
Apache License 2.0
537 stars 44 forks source link

Add ability to close Channel after remaining elements have been taken #721

Open steinybot opened 3 weeks ago

steinybot commented 3 weeks ago

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.

fwbrasil commented 3 weeks ago

@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?