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