MCPcopy Create free account
hub / github.com/microsoft/vscode-cpptools / emit

Function emit

Extension/src/Utility/Eventing/dispatcher.ts:406–426  ·  view source on GitHub ↗
(name: string, ...variableArgs: any[])

Source from the content-addressed store, hash-verified

404export async function emit<TResult>(name: string, text: string, data: ArbitraryObject): Promise<TResult | EventStatus>;
405export async function emit<TResult>(name: string): Promise<TResult | EventStatus>;
406export 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 */
429export async function emitNow<TResult>(name: string, descriptors: Descriptors, text: string): Promise<TResult | EventStatus>;

Callers 2

emitFunction · 0.90
newEventFunction · 0.90

Calls 4

isSubscribedFunction · 0.85
expandVariableArgsFunction · 0.85
drainFunction · 0.85
pushMethod · 0.80

Tested by

no test coverage detected