I am trying to aggregate the responses after running a loop and having promises being called each time. However, the function does not wait for all the promises to be done and returns undefined.
getAllPluginImpls(): DesktopPluginDefinitionImpl[] {
let pluginArray: DesktopPluginDefinitionImpl[] = [];
let promises = [];
Array.from(this.pluginMap.keys()).forEach(id =>
promises.push(this.pluginManager.findPluginDefinition(id).then(
def => {
console.log("id");
console.log(id);
console.log("def");
console.log(def);
let pluginImpl = def as DesktopPluginDefinitionImpl;
pluginArray.push(pluginImpl);
}
)
)
);
Promise.all(promises).then(s => {
console.log("end reached :(");
console.log(pluginArray);
return pluginArray;
});
}
map(), not.forEach()Promise.all()will give you what you want.