pub trait BackgroundQueue: Send + Sync + Sized + 'static {
    type Task: Send + Sync + Sized + 'static;

    // Required method
    fn batch_process<const N: usize>(
        tasks: UnboundedRange<'_, Self::Task, N>
    ) -> impl Future<Output = ()> + Send;

    // Provided method
    fn auto_batch<const N: usize>(task: Self::Task)
       where Self: LocalQueue<N, BufferCell = BufferCell<Self::Task>> { ... }
}
Expand description

Fire and forget auto-batched queue

§Example

struct EchoQueue;

#[local_queue]
impl BackgroundQueue for EchoQueue {
  type Task = (usize, oneshot::Sender<usize>);

  fn batch_process<const N: usize>(tasks: UnboundedRange<'_, Self::Task, N>) -> impl Future<Output = ()> + Send {
    for (val, tx) in tasks.into_bounded().into_iter() {
      tx.send(val).ok();
    }
  }
}

Required Associated Types§

source

type Task: Send + Sync + Sized + 'static

Required Methods§

source

fn batch_process<const N: usize>( tasks: UnboundedRange<'_, Self::Task, N> ) -> impl Future<Output = ()> + Send

Provided Methods§

source

fn auto_batch<const N: usize>(task: Self::Task)
where Self: LocalQueue<N, BufferCell = BufferCell<Self::Task>>,

Process task in background

§Panics

Panics if called from outside of the Tokio runtime

Object Safety§

This trait is not object safe.

Implementors§