Trait BackgroundQueue

Source
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

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§