(name: string, ...variableArgs: any[])
| 404 | export async function emit<TResult>(name: string, text: string, data: ArbitraryObject): Promise<TResult | EventStatus>; |
| 405 | export async function emit<TResult>(name: string): Promise<TResult | EventStatus>; |
| 406 | export async function emit<TResult>(name: string, ...variableArgs: any[]): Promise<TResult | EventStatus> { |
| 407 | // quickly check if there are any possible handlers for this event |
| 408 | if (isSubscribed(name)) { |
| 409 | const descriptors = variableArgs[0] instanceof Descriptors ? variableArgs.shift() : Descriptors.none; |
| 410 | |
| 411 | // create a promise that will be resolved when the event is dispatched |
| 412 | const result = new ManualPromise<TResult | EventStatus>(); |
| 413 | |
| 414 | // add the event to the queue |
| 415 | queue.push(expandVariableArgs(variableArgs, { name, variableArgs, descriptors, completed: result })); |
| 416 | |
| 417 | // if the queue was empty, start it draining the queue |
| 418 | if (DispatcherBusy.isCompleted) { |
| 419 | void drain(); // don't wait for the queue to finish draining |
| 420 | } |
| 421 | |
| 422 | // return the promise |
| 423 | return result; |
| 424 | } |
| 425 | return Continue; |
| 426 | } |
| 427 | |
| 428 | /** immediately dispatches an event */ |
| 429 | export async function emitNow<TResult>(name: string, descriptors: Descriptors, text: string): Promise<TResult | EventStatus>; |
no test coverage detected