Skip to main content

ddd_toolkit_core/
async_domain_event_publisher.rs

1use crate::DomainEvent;
2use std::future::Future;
3use std::pin::Pin;
4
5/// **English:**<br>
6/// Publishes domain events asynchronously. Implementations define the event type and
7/// error type; `publish` borrows both the publisher and event until its returned future completes.
8///
9/// **日本語:**<br>
10/// ドメインイベントを非同期に発行します。実装側がイベント型とエラー型を定義します。
11/// `publish` が返す future の完了まで、パブリッシャーとイベントの借用が保持されます。
12pub trait AsyncDomainEventPublisher {
13    /// **English:**<br>
14    /// Event type accepted by this publisher.
15    ///
16    /// **日本語:**<br>
17    /// このパブリッシャーが受け付けるイベント型です。
18    type Event: DomainEvent;
19    /// **English:**<br>
20    /// Error returned when publishing fails.
21    ///
22    /// **日本語:**<br>
23    /// 発行に失敗したときに返されるエラー型です。
24    type Error;
25
26    /// **English:**<br>
27    /// Publishes `event` and resolves to `Ok(())` on success or the implementation's
28    /// error on failure. The returned future is `Send` and borrows `self` and `event` for `'a`.
29    ///
30    /// **日本語:**<br>
31    /// `event` を発行し、成功時は `Ok(())`、失敗時は実装が定めるエラーで解決します。
32    /// 返される future は `Send` であり、`'a` の間 `self` と `event` を借用します。
33    fn publish<'a>(
34        &'a mut self,
35        event: &'a Self::Event,
36    ) -> Pin<Box<dyn Future<Output = Result<(), Self::Error>> + Send + 'a>>;
37}