You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/core/README.md
+29-1Lines changed: 29 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -127,7 +127,35 @@ The module uses a `TransactionalEventEmitter` for reliable event emission. This
127
127
}]
128
128
);
129
129
```
130
-
-**Event Contract:** Ensure that your event classes implement the `InboxOutboxEvent` interface for consistency and clarity.
130
+
131
+
### Synchronous vs Asynchronous Emission
132
+
133
+
The `TransactionalEventEmitter` provides two methods for emitting events:
134
+
135
+
-**emit:**
136
+
- Fires the event and attempts immediate delivery to listeners, but does **not** wait for listeners to finish execution.
137
+
- Use this when you want to trigger event delivery and continue your logic without waiting for listeners to complete.
138
+
139
+
-**emitAsync:**
140
+
- Fires the event and **waits for all listeners to finish execution** before resolving.
141
+
- Use this when you need to ensure that all listeners have processed the event before proceeding (e.g., for transactional workflows or when listener side effects are required before continuing).
142
+
143
+
**Example:**
144
+
```typescript
145
+
// Wait for all listeners to finish processing the event
> **Note:** Use `emitAsync` if you need to wait for listeners to execute and complete before moving on. Use `emit` if you want to fire-and-forget the event delivery.
156
+
157
+
### Event Contract:
158
+
Ensure that your event classes implement the `InboxOutboxEvent` interface for consistency and clarity.
0 commit comments