An asynchronous event broker that support a single event handler.
ListenEvent extends BaseEvent
The type of event to listen for.
ReplyEvent extends BaseEvent = ListenEvent
The type of event to reply with.
private
abstract
_listener: AsyncGenerator<ReplyEvent | undefined, ReplyEvent | void, ListenEvent | { [stopSymbol]?: boolean; }>
private
abstract
_listenerId: ListenerID
emit(event: ListenEvent): Promise<boolean>
Sends an event to the listener.
emitWithReply(event: ListenEvent): Promise<ReplyEvent>
Sends an event and waits for a reply.
private
listen(listener: AsyncBrokerListener<ListenEvent, ReplyEvent>): AsyncGenerator<ReplyEvent | undefined, ReplyEvent | void, ListenEvent | { [stopSymbol]?: boolean; }>
An asynchronous generator function that listens for events.
off(listenerId: ListenerID): Promise<boolean>
Stops listening for events.
on(handler: AsyncEventHandler<ListenEvent, ReplyEvent>): Promise<ListenerID | undefined>
Starts listening for events.
once(handler: AsyncEventHandler<ListenEvent, ReplyEvent>): Promise<ListenerID | undefined>
Starts listening for sigle event and then off.
deprecated
send(event: ListenEvent): Promise<boolean>
alias for emit method
deprecated
sendAndWaitForReply(event: ListenEvent): Promise<ReplyEvent>
alias for emitWithReply method
deprecated
start(handler: AsyncEventHandler<ListenEvent, ReplyEvent>): Promise<ListenerID | undefined>
alias for on method
deprecated
stop(listenerId: ListenerID): Promise<boolean>
alias for off method