hawkw / thingbuf

in-place allocation-reusing queues for Rust
MIT License
292 stars 24 forks source link

Adding `remaining()` and `capacity()` methods to `Sender` and `Receiver` #71

Closed jcrevier closed 7 months ago

jcrevier commented 2 years ago

Hello! This crate is very neat. It would be very helpful for metrics if mpsc::Sender and mpsc::Receiver channel handles exposed a way to determine the capacity and remaining slots. The ThingBuf queue has a remaining() and a capacity() method, so it seems odd that Sender or Receiver don't. I'm open to writing up a PR to add this, but I noticed that the implementation of Sender and Receiver was a bit different than ThingBuf -- is there any reason these weren't exposed? From a quick glance it seems like they would be easy to add to Sender and Receiver by just using the len() and capacity() methods from self.inner.core.core

hawkw commented 2 years ago

Yes, I believe it should be possible to add these methods by just forwarding them from the Core type; not having them on MPSC channels was just an oversight on my part, I think. I'd happily merge a PR that adds them!

kiranshila commented 1 year ago

Just wanted to give this a quick bump - the PR looks to be in decent shape. If there is anything I can do to help get it merged, let me know - as it would be very useful for one of my projects!

jcrevier commented 1 year ago

@kiranshila so I think the only real blocker is that there's some weird behavior around the len() method that merging this PR would expose -- I think when dropping the channel. See the failing doc tests in the PR. Eliza was going to look into it, and I was also going to try to look into it..I haven't had the time and I suspect the same for Eliza.

jcrevier commented 7 months ago

Glad to see this merged 😄 🎉