MCPcopy Index your code
hub / github.com/microsoft/vscode-cpptools / initialize

Function initialize

Extension/src/Utility/Async/factory.ts:13–26  ·  view source on GitHub ↗

calls/awaits any .init in the result from the factory

(instance: WithInit<ReturnType<TFactory>> | Promise<WithInit<ReturnType<TFactory>>>, args: any[])

Source from the content-addressed store, hash-verified

11export function Factory<TFactory extends (...args: Parameters<TFactory>) => ReturnType<TFactory>>(factory: TFactory): new (...args: Parameters<TFactory>) => Promise<Awaited<ReturnType<TFactory>>> {
12 /** calls/awaits any .init in the result from the factory */
13 async function initialize(instance: WithInit<ReturnType<TFactory>> | Promise<WithInit<ReturnType<TFactory>>>, args: any[]) {
14 if (instance !== null && instance !== undefined) {
15 if (is.promise(instance)) {
16 instance = await instance;
17 }
18
19 // if .init is a function, call it, if it's a promise, await it
20 const pInit = typeof instance.init === 'function' ? instance.init(args) : instance.init;
21 if (is.promise(pInit)) {
22 await pInit;
23 }
24 }
25 return instance;
26 }
27
28 class AsyncFactory extends Promise<ReturnType<TFactory>> {
29 protected factory: TFactory;

Callers 1

constructorMethod · 0.70

Calls 2

promiseMethod · 0.80
initMethod · 0.45

Tested by

no test coverage detected