Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resize the capacity of bounded channels #144

Open
Frando opened this issue Apr 19, 2024 · 2 comments
Open

Resize the capacity of bounded channels #144

Frando opened this issue Apr 19, 2024 · 2 comments
Labels
help wanted Extra attention is needed

Comments

@Frando
Copy link

Frando commented Apr 19, 2024

It would be neat if bounded channels could be resized, to increase or decrease the allocated capacity, like Vec::shrink_to and Vec::reserve_exact.

@Frando Frando changed the title Resize bounded channels capacity Resize the capacity of bounded channels Apr 19, 2024
@zesterer
Copy link
Owner

I would indeed be neat, but potentially annoying to implement properly. Sadly, I don't currently have the time to implement substantial features like this.

@zesterer zesterer added the help wanted Extra attention is needed label Apr 23, 2024
@rakbladsvalsen
Copy link

This issue is similar to #148, where you basically can end up with memory leaks due to the way flume internally works. Not quite the same issue, but memory leaks can't be avoided because there's no shrink_to_fit in any channel flavor.

I believe the "proper" implementation would be to:

  1. provide proxy methods to the internal queue's shrink_to_fit and reserve_exact methods, among others, or
  2. provide something like alter_queue(Fn(&mut VecDeque))/get_queue_mut() -> &mut VecDeque so that the user is free to do whatever they want, including, but not limited to shrink_to_fit, reserve_exact, etc. Although this could potentially cause bugs (?), I don't think it's that bad. I've seen libraries like reqwest use weird fn names to convey the fact that, by using them, they might cause issues or problems (example).

Resizing bounded channels might be actually hard to implement because you'd need a way to change how the internal Channel works (its capacity isn't stored in a mutable/atomic integer), but you can probably achieve whatever you're trying to do with wrapped unbounded channels + the stuff I implemented in my PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants