pub trait BatchReducer: Send + Sync + Sized + 'static {
    type Task: Send + Sync + Sized + 'static;
    type impl_trait_batch_reduce_0<'async_trait, const N: usize, F, R: 'async_trait>: Future<Output = Option<R>> + 'async_trait + Send
       where Self: LocalQueue<N, BufferCell = BufferCell<Self::Task>>,
             F: for<'a> FnOnce(UnboundedSlice<'a, Self::Task, N>) -> Pin<Box<dyn Future<Output = R> + Send + 'a>> + Send + 'async_trait;

    // Required method
    fn batch_reduce<'async_trait, const N: usize, F, R: 'async_trait>(
        task: Self::Task,
        f: F
    ) -> Self::impl_trait_batch_reduce_0<'async_trait, N, F, R>
       where Self: LocalQueue<N, BufferCell = BufferCell<Self::Task>>,
             F: for<'a> FnOnce(UnboundedSlice<'a, Self::Task, N>) -> Pin<Box<dyn Future<Output = R> + Send + 'a>> + Send + 'async_trait;
}
Expand description

Auto-batched queue whereby batches are reduced by a closure

Example

struct Accumulator;

#[local_queue]
impl BatchReducer for Accumulator {
  type Task = usize;
}

let sum = Accumulator::batch_reduce(9000, |slice| {
  Box::pin(async move { slice.into_bounded().iter().sum::<usize>() })
}).await;

Required Associated Types§

source

type Task: Send + Sync + Sized + 'static

source

type impl_trait_batch_reduce_0<'async_trait, const N: usize, F, R: 'async_trait>: Future<Output = Option<R>> + 'async_trait + Send where Self: LocalQueue<N, BufferCell = BufferCell<Self::Task>>, F: for<'a> FnOnce(UnboundedSlice<'a, Self::Task, N>) -> Pin<Box<dyn Future<Output = R> + Send + 'a>> + Send + 'async_trait

Required Methods§

source

fn batch_reduce<'async_trait, const N: usize, F, R: 'async_trait>( task: Self::Task, f: F ) -> Self::impl_trait_batch_reduce_0<'async_trait, N, F, R>where Self: LocalQueue<N, BufferCell = BufferCell<Self::Task>>, F: for<'a> FnOnce(UnboundedSlice<'a, Self::Task, N>) -> Pin<Box<dyn Future<Output = R> + Send + 'a>> + Send + 'async_trait,

Enqueue and auto-batch task, using reducer fn once per batch. The local_queue macro will implement batch_reduce

Implementors§