mediator_sys/mediator/asynchronous/basic/
interface.rs

1use async_trait::async_trait;
2use std::{fmt::Debug, sync::mpsc::TryRecvError};
3
4/// Publish an event `Ev` asynchronously from within a handler.
5#[async_trait]
6pub trait AsyncMediatorInternal<Ev: Debug> {
7    async fn publish(&self, event: Ev);
8}
9
10/// Send a request `Req` asynchronously for processing to the mediator.
11/// This will call the handler.
12#[async_trait]
13pub trait AsyncMediatorInternalHandle<Ev: Debug> {
14    async fn send<Req>(&self, req: Req)
15    where
16        Req: Send,
17        Self: AsyncRequestHandler<Req, Ev>;
18}
19
20/// Process the next event `Ev` from the channel asynchronously.
21/// This will call all listeners with a clone of that event.
22#[async_trait]
23pub trait AsyncMediatorInternalNext {
24    async fn next(&self) -> Result<(), TryRecvError>;
25}
26
27/// Handles the request `Req` asynchronously.
28/// Implemented by the user.
29#[async_trait]
30pub trait AsyncRequestHandler<Req, Res>
31where
32    Self: Sync,
33{
34    async fn handle(&self, req: Req);
35}