smol-rs / async-broadcast

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

API to disable waiting for active receivers #36

Closed zeenix closed 1 year ago

zeenix commented 1 year ago

While typically the sender would want to await active receivers, there are some cases where it'd be desirable for sender to not wait but rather not block. One example would be where there are multiple channels to send out to. The use case for using multiple channels would typically be to avoid needlessly waking up tasks that are only interested in the message if it qualifies a certain criteria. Since async-broadcast doesn't provide API for setting up sender-side filters on receivers (with the current implementation, I'm not even sure that's possible), users will have to split up the channels, one for each filter. There may also be other use cases.

So let introduce a new concept of await-active mode that is enabled by default and represents the status-quo behavior. Whe disabled, Sender::broadcast will not wait for active receivers but rather return immediately with a SendError.

Fixes #35.