Asynchronous broadcast channel with backpressure

I'm looking for a channel to pass messages. The channel should be:

  • asynchronous (i.e. non-blocking)
  • allow receivers to be added and removed at any time
  • send each message to every receiver that is currently attached/listening
  • provide back-pressure, i.e. if one receiver is slow, the sender should wait and be woken up later (through async)

I have looked at various existing channels, of which none seems to fit:

My use case is radiorust::flow which I would like to extend to provide backpressure.

I would also be interested to learn how I can implement such a channel myself (using atomic operations?), but I feel like it's not easy to do it properly, especially when tasks need to be woken up also.

I believe the Semaphore is a good choice for this item. The receiver calls release. The sender calls wait. The Semaphore is initialized to the threshold at which back-pressure is applied.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.