i have a code that needs many different promises to solve before proceding with some computation. just for info, the promises are concerning accessing database.
for example:
const house= await database.getTheHouse();
const person= await database.getThePerson();
const address= await database.getTheAdress();
...
N-data= await database.getNData();
compute(house,person,address)
so I wanted something like this, to increase the performance launching asynchronous but i have problems with the types of the array
listPromises=[ database.getHouse(), database.getPerson(),database.getAdress(), ...];
[house,person,address]= await Promise.all(listPromises);
compute(house,person,address);
then now i'm trying to do a forEach on the listPromises, but not sure what is the best approach, if any has found the same issue and has any advice, would be great.
let house;
let person;
let ...;
listOfFieldsNeeded.foreach(async element =>{
switch (element){
case House:
house= await database.getHouse();
break;
case Person:
person= await database.getPerson();
break;
...
}
})
...but here in the code, i cant use person because is used before asignation :/