smol-rs / async-broadcast

Async broadcast channels
Apache License 2.0
163 stars 26 forks source link

Dropping all `Receiver`s should not `close` channel #45

Closed jnhyatt closed 1 year ago

jnhyatt commented 1 year ago

Sender has a public API new_receiver that allows for Receivers to be created without cloning an existing Receiver. This means that if all Receivers are dropped and then new_receiver is called, the channel will only give Closed results for send and recv. This is surprising behavior since I was expecting dropping all receivers to result in any sent messages simply being cast into the void, and then picked up again when a receiver was created.

If this is intentional, I'm curious what the reason for this design is. At the least I'd expect a closed channel to be reopenable by creating new Receivers. What's the reasoning behind the current API, and could it change to either option presented here?

zeenix commented 1 year ago

since I was expecting dropping all receivers to result in any sent messages simply being cast into the void, and then picked up again when a receiver was created.

Not if you read the docs. :)

There was a similar request not too long ago (#34) and it ended up with https://github.com/smol-rs/async-broadcast/pull/36. I think you can make use of that with inactive receiver concept to achieve your goals.