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: content/techniques/events.md
+20-5Lines changed: 20 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -50,7 +50,7 @@ EventEmitterModule.forRoot({
50
50
});
51
51
```
52
52
53
-
#### Dispatching Events
53
+
#### Dispatching events
54
54
55
55
To dispatch (i.e., fire) an event, first inject `EventEmitter2` using standard constructor injection:
56
56
@@ -72,7 +72,7 @@ this.eventEmitter.emit(
72
72
);
73
73
```
74
74
75
-
#### Listening to Events
75
+
#### Listening to events
76
76
77
77
To declare an event listener, decorate a method with the `@OnEvent()` decorator preceding the method definition containing the code to be executed, as follows:
> warning **Warning** Event subscribers cannot be request-scoped.
87
87
88
-
The first argument can be a `string` or `symbol` for a simple event emitter and a `string | symbol | Array<string | symbol>` in a case of a wildcard emitter.
88
+
The first argument can be a `string` or `symbol` for a simple event emitter and a `string | symbol | Array<string | symbol>` in a case of a wildcard emitter.
89
89
90
90
The second argument (optional) is a listener options object as follows:
> info **Hint**`EventEmitter2` class provides several useful methods for interacting with events, like `waitFor` and `onAny`. You can read more about them [here](https://github.com/EventEmitter2/EventEmitter2).
144
143
144
+
#### Preventing event loss
145
+
146
+
Events triggered before or during the `onApplicationBootstrap` lifecycle hook—such as those from module constructors or the `onModuleInit` method—may be missed because the `EventSubscribersLoader` might not have finished setting up the listeners.
147
+
148
+
To avoid this issue, you can use the `waitUntilReady` method of the `EventEmitterReadinessWatcher`, which returns a promise that resolves once all listeners have been registered. This method can be called in the `onApplicationBootstrap` lifecycle hook of a module to ensure that all events are properly captured.
0 commit comments