pub trait Handler<T>: Send + Sync
where T: Message,
{ type Error: Send + Sync; // Required method fn handle<'life0, 'async_trait>( &'life0 self, command: Envelope<T> ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; }
Expand description

A software component that is able to handle [Command]s of a certain type, and mutate the state as a result of the command handling, or fail.

In an event-sourced system, the [Command] Handler should use an Aggregate to evaluate a [Command] to ensure business invariants are respected.

Required Associated Types§

source

type Error: Send + Sync

The error type returned by the Handler while handling a [Command].

Required Methods§

source

fn handle<'life0, 'async_trait>( &'life0 self, command: Envelope<T> ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Handles a [Command] and returns an error if the handling has failed.

Since [Command]s are solely modifying the state of the system, they do not return anything to the caller but the result of the operation (expressed by a Result type).

Implementors§

source§

impl<T, Err, F, Fut> Handler<T> for F
where T: Message + Send + Sync + 'static, Err: Send + Sync, F: Send + Sync + Fn(Envelope<T>) -> Fut, Fut: Send + Sync + Future<Output = Result<(), Err>>,

§

type Error = Err