crossbeam-rs / crossbeam

Tools for concurrent programming in Rust
Apache License 2.0
7.49k stars 470 forks source link

Feature: Send multiple items at once via one Sender #1134

Open kimono-koans opened 2 months ago

kimono-koans commented 2 months ago

Just as there is a Receiver::iter and a Receiver::try_iter, where a Receiver can receive multiple items at once, it would seem there should also be an interface where a Sender can send multiple items at once from a single sender.

Maybe something which looks like:

pub fn send_from_slice(&self, t: &[T]) -> Result<(), SendError<T>
pub fn send_iter(&self, t: Iter<'_, T>) -> Result<(), SendError<T>

Perhaps I'm mistaken, but an interface like this, might reduce the amount of time spent contending on any locks, or reduce the amount of times a buffer Vec needs to realloc.

Why am I requesting this? I am working with a previously existing interface, which takes a Sender as a parameter. I'd also guess that sending in parallel would introduce overhead, and sometimes I'd like to maintain the order of when each item was sent.

Thanks!