1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
use crateEventRestorationGuard;
use crate::;
/// **English:**<br>
/// Publishes the events currently held by `aggregate` through `publisher`.
///
/// Events are passed to [`DomainEventPublisher::publish`] in the order returned by
/// [`AggregateRoot::pull_events`]. If a publish operation returns an error, all events pulled at
/// the start of this call are recorded back into the aggregate before that error is returned.
/// This restoration does not undo publishes that already succeeded. If every publish succeeds,
/// the events are removed from the aggregate and the function returns `Ok(())`.
///
/// The function may panic if the aggregate's [`AggregateRoot::pull_events`] or
/// [`AggregateRoot::record_event`] implementation panics. It does not impose additional
/// synchronization; the aggregate and publisher must be mutably borrowed by the caller for the
/// duration of the dispatch.
///
/// **日本語:**<br>
/// `aggregate` が現在保持しているイベントを `publisher` 経由で発行します。
///
/// イベントは [`AggregateRoot::pull_events`] が返した順序で [`DomainEventPublisher::publish`]
/// に渡されます。発行処理がエラーを返すと、この呼び出しの開始時に取り出したすべての
/// イベントを集約へ記録し直してから、そのエラーを返します。すでに成功した発行処理は
/// 取り消されません。すべての発行に成功した場合、イベントは集約から削除され、`Ok(())`
/// を返します。
///
/// 集約の [`AggregateRoot::pull_events`] または [`AggregateRoot::record_event`] の実装が
/// パニックすると、この関数もパニックする可能性があります。この関数は追加の同期を
/// 行わないため、呼び出し側はディスパッチ中、集約とパブリッシャーを可変借用します。