zesterer / flume

A safe and fast multi-producer, multi-consumer channel.
https://crates.io/crates/flume
Apache License 2.0
2.47k stars 85 forks source link

`SendFut::poll` should return `Poll::Pending` for rendezvous channels when no item is queued #140

Open thomaseizinger opened 11 months ago

thomaseizinger commented 11 months ago

I have a rendezvous channel with one Receiver and multiple senders, each sender sitting in its own task. I'd like these tasks to wake up when the Receiver gets dropped. For this to work, the task needs to suspend on SendSink::poll_ready.

Today, this does not work because SendFut returns Poll::Ready if it does not have anything to do: https://github.com/zesterer/flume/blob/fcf384956a7badd003c4eca43da5174f4e0c86a0/src/async.rs#L195-L198

I don't think this is correct. Instead of always returning Poll::Ready, I think the future needs to check, whether there would be capacity to send an item and if there isn't like in the case of a rendezvous channel, register a waker and return Poll::Pending.