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
> info **Hint** Import the `EventEmitter2` from the `@nestjs/event-emitter` package.
62
+
63
+
Then use it in a class as follows.
64
+
65
+
```typescript
66
+
this.eventEmitter.emit(
67
+
'order.created',
68
+
newOrderCreatedEvent({
69
+
orderId: 1,
70
+
payload: {},
71
+
}),
72
+
);
73
+
```
74
+
75
+
#### Listening to Events
54
76
55
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:
> info **Hint** Import the `EventEmitter2` from the `@nestjs/event-emitter` package.
91
-
92
-
Then use it in a class as follows.
93
-
94
-
```typescript
95
-
this.eventEmitter.emit(
96
-
'order.created',
97
-
newOrderCreatedEvent({
98
-
orderId: 1,
99
-
payload: {},
100
-
}),
101
-
);
102
-
```
103
-
104
104
> 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).
0 commit comments