Merge branch 'feat/inda-383-daily-stat' into 'main'
[ProtonMail-WebClient.git] / packages / docs-shared / lib / Events / InternalEventBusInterface.ts
blob986276c7c76a9cbd38dfa6f209fcacc1e1cdda5e
1 import type { InternalEventType } from './InternalEventType'
2 import type { InternalEventHandlerInterface } from './InternalEventHandlerInterface'
3 import type { InternalEventInterface } from './InternalEventInterface'
4 import type { InternalEventPublishStrategy } from './InternalEventPublishStrategy'
6 export interface InternalEventBusInterface {
7   /**
8    * Associate an event handler with a certain event type
9    * @param handler event handler instance
10    * @param eventType event type to associate with
11    */
12   addEventHandler(handler: InternalEventHandlerInterface, eventType: InternalEventType): void
14   addEventCallback<Data = unknown>(callback: (data: Data) => void, eventType: string): () => void
16   removeEventHandler(handler: InternalEventHandlerInterface, eventType: string): void
18   /**
19    * Asynchronously publish an event for handling
20    * @param event internal event object
21    */
22   publish<Payload = unknown>(event: InternalEventInterface<Payload>): void
23   /**
24    * Synchronously publish an event for handling.
25    * This will await for all handlers to finish processing the event.
26    * @param event internal event object
27    * @param strategy strategy with which the handlers will process the event.
28    * Either all handlers will start at once or they will do it sequentially.
29    */
30   publishSync(event: InternalEventInterface, strategy: InternalEventPublishStrategy): Promise<void>
32   deinit(): void