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

Add tokio::sync::mpsc::UnboundedSender::send_many to improve the case of sending many values to an unbounded channel at once. #4643

Open
FSMaxB opened this issue Apr 28, 2022 · 2 comments
Labels
A-tokio Area: The main tokio crate C-feature-request Category: A feature request. M-sync Module: tokio/sync

Comments

@FSMaxB
Copy link
Contributor

FSMaxB commented Apr 28, 2022

Currently mpsc::UnboundedSender don't allow sending more than one value at once, so when sending multiple values this needs to be done manually by calling it multiple times.

Wouldn't it be possible to add a method that takes an Iterator and performs the internal atomic operations to reserve space only once using the size_hint when available (at least if no new blocks need to be added and the size hint is reliable).

fn send_many<Iter>(&self, messages: Iter) -> Result<(), SendError<T>>
where
	Iter: Iterator<Item = T>
{
}

Of course this would need to be careful because the size_hint may not be trustworthy.

I'm not sure if that feature would make sense for bounded channels as well since the potentially empty slots from allocating to much in advance would reduce the channels capacity temporarily.

@FSMaxB FSMaxB added A-tokio Area: The main tokio crate C-feature-request Category: A feature request. labels Apr 28, 2022
@FSMaxB
Copy link
Contributor Author

FSMaxB commented Apr 28, 2022

The bound could also require ExactSizeIterator.

@Darksonn Darksonn added the M-sync Module: tokio/sync label Apr 28, 2022
@Darksonn
Copy link
Contributor

It's probably possible to implement this. Question is if we want to. Thoughts @carllerche?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate C-feature-request Category: A feature request. M-sync Module: tokio/sync
Projects
None yet
Development

No branches or pull requests

2 participants