nitinol_process/channel/
forget.rs1use std::fmt::Debug;
2
3use async_trait::async_trait;
4use nitinol_core::command::Command;
5use crate::errors::ChannelDropped;
6use crate::{Context, EventApplicator, Process, ProcessApplier, CommandHandler};
7
8pub struct NonBlockingEntrustHandler<C: Command> {
9 pub(crate) command: C,
10}
11
12#[async_trait]
13impl<C: Command, T: Process> ProcessApplier<T> for NonBlockingEntrustHandler<C>
14where
15 T: CommandHandler<C>,
16 T::Rejection: Debug,
17 T: EventApplicator<<T as CommandHandler<C>>::Event>,
18{
19 async fn apply(self: Box<Self>, entity: &mut T, ctx: &mut Context) -> Result<(), ChannelDropped> {
20 match entity.handle(self.command, ctx).await {
21 Ok(event) => {
22 entity.apply(event, ctx).await;
23 ctx.sequence += 1;
24 }
25 Err(rejection) => {
26 tracing::error!("An error occurred: {:?}", rejection);
27 }
28 }
29 Ok(())
30 }
31}