Processor

Trait Processor 

Source
pub trait Processor:
    'static
    + Send
    + Clone {
    type Key: 'static + Debug + Eq + Hash + Clone + Send + Sync;
    type Input: Send;
    type Output: Send;
    type Error: Send + Clone + Display + Debug;
    type Resources: Send;

    // Required methods
    fn acquire_resources(
        &self,
        key: Self::Key,
    ) -> impl Future<Output = Result<Self::Resources, Self::Error>> + Send;
    fn process(
        &self,
        key: Self::Key,
        inputs: impl Iterator<Item = Self::Input> + Send,
        resources: Self::Resources,
    ) -> impl Future<Output = Result<Vec<Self::Output>, Self::Error>> + Send;
}
Expand description

Process a batch of inputs for a given key.

Should be cheap to clone.

Required Associated Types§

Source

type Key: 'static + Debug + Eq + Hash + Clone + Send + Sync

The key used to group inputs.

Source

type Input: Send

The input type for each item.

Source

type Output: Send

The output type for each item.

Source

type Error: Send + Clone + Display + Debug

The error type that can be returned when processing a batch.

Source

type Resources: Send

The resources that will be acquired before processing each batch, and can be used during processing.

Required Methods§

Source

fn acquire_resources( &self, key: Self::Key, ) -> impl Future<Output = Result<Self::Resources, Self::Error>> + Send

Acquire resources to be used for processing the next batch with the given key.

This method is called before processing each batch.

For BatchingPolicy::Immediate, the batch will keep accumulating items until the resources are acquired.

Can be used to e.g. acquire a database connection from a pool.

Source

fn process( &self, key: Self::Key, inputs: impl Iterator<Item = Self::Input> + Send, resources: Self::Resources, ) -> impl Future<Output = Result<Vec<Self::Output>, Self::Error>> + Send

Process the batch.

The order of the outputs in the returned Vec must be the same as the order of the inputs in the given iterator.

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§