Trait mz_ore::channel::ReceiverExt
source · pub trait ReceiverExt<T: Send> {
// Required method
fn recv_many<'life0, 'async_trait>(
&'life0 mut self,
max: usize
) -> Pin<Box<dyn Future<Output = Option<Vec<T>>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
}
async
only.Expand description
Extensions for the receiving end of asynchronous channels.
Required Methods§
sourcefn recv_many<'life0, 'async_trait>(
&'life0 mut self,
max: usize
) -> Pin<Box<dyn Future<Output = Option<Vec<T>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn recv_many<'life0, 'async_trait>(
&'life0 mut self,
max: usize
) -> Pin<Box<dyn Future<Output = Option<Vec<T>>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Receives all of the currently buffered elements on the channel, up to some max.
This method returns None
if the channel has been closed and there are no remaining
messages in the channel’s buffer.
If there are no messages in the channel’s buffer, but the channel is not yet closed, this method will sleep until a message is sent or the channel is closed. When woken it will return up to max currently buffered elements.
§Cancel safety
This method is cancel safe. If recv_many
is used as the event in a select!
statement
and some other branch completes first, it is guaranteed that no messages were received on
this channel.
§Max Buffer Size
The provided max buffer size should always be less than the total capacity of the channel. Otherwise a good value is probably a fraction of the total channel size, or however large a batch that your receiving component can handle.
TODO(parkmycar): We should refactor this to use impl Iterator
instead of Vec
when
“impl trait in trait” is supported.