* Subscribe to an event once (automatically unsubscribes after first emission) * @param event - Event name to listen for * @param callback - Function to call when event is emitted * @returns Unsubscribe function
(
event: T,
callback: (event: TEvents[T]) => void,
)
| 35 | * @returns Unsubscribe function |
| 36 | */ |
| 37 | once<T extends keyof TEvents>( |
| 38 | event: T, |
| 39 | callback: (event: TEvents[T]) => void, |
| 40 | ): () => void { |
| 41 | const unsubscribe = this.on(event, (eventPayload) => { |
| 42 | callback(eventPayload) |
| 43 | unsubscribe() |
| 44 | }) |
| 45 | return unsubscribe |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Unsubscribe from an event |