I have this piece of code that builds a control in a base class in javascript and it works but there is a problem with it. The problem is when I run async function the code doesn’t wait till the build() function is complete. The static create() method cannot be an async function because it will not make the rest of the code work. My question is how do I make the getPromise() function wait to build the control and then run the last line of code to complete the build of the component?
static create(selector, object) {
let self = this;
if(!this.instances.includes(selector)) {
this.instances[selector] = object;
}
async function getPromise() {
await self.instances[selector].build();
}
getPromise();
return self.instances[selector];
}