Trait stack_queue::BackgroundQueue
source · pub trait BackgroundQueue: Send + Sync + Sized + 'static {
type Task: Send + Sync + Sized + 'static;
type impl_trait_batch_process_0<'async_trait, const N: usize>: Future<Output = ()> + 'async_trait + Send;
// Required method
fn batch_process<'async_trait, const N: usize>(
tasks: UnboundedRange<'async_trait, Self::Task, N>
) -> Self::impl_trait_batch_process_0<'async_trait, N>;
// 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>);
async fn batch_process<const N: usize>(tasks: UnboundedSlice<'async_trait, Self::Task, N>) {
let tasks = tasks.into_bounded().to_vec();
for (val, tx) in tasks.into_iter() {
tx.send(val).ok();
}
}
}