smol-rs / async-broadcast

Async broadcast channels

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Allow Sender to not await active receivers

zeenix opened this issue · comments

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.

Two solutions come to mind:

  1. We extend the scope of overflow mode. When it's set to true, Sender doesn't wait for active receivers and just drops the message.
  2. Introduce a new await-active-receiver mode that when set, means Sender not waiting for active receivers. The question would be if broadcast should just succeed when there are no active receivers of error out, in case sender wanted the message back if nobody could receive it? I'm leaning towards the latter.