tokio
tokio copied to clipboard
Add tokio::sync::mpsc::UnboundedSender::send_many to improve the case of sending many values to an unbounded channel at once.
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.
The bound could also require ExactSizeIterator
.
It's probably possible to implement this. Question is if we want to. Thoughts @carllerche?