Dear All,
I am trying to execute a batch process to query the database. Batch will have hundreds of queries and tried to execute through Promise.all. But it still working as a top down approach only. But same Promise.all is working fine if we test with sample timer function instead of pjs.query.
IN the below code DoSomethingAsync() is called three timeswhich are not executed in parallel. It is executed one by one only. Kindly suggest a solution for resolving this issue
Code Reference:
var dateFormat = require(‘dateformat’);
async function DoSomethingAsync(){
return new Promise((resolve) => {
var Result1 = pjs.query(query1);
var Result2 = pjs.query(query2 based on Result1 result);
var Result3 = pjs.query(query3 based on Result2 result););
var FinalResult = pjs.query(query4 based on Result3 result););
resolve(FinalResult);
});
}
async function sampleAPI(req, res){
var globalContents=[];
var promises=[];
promises.push(DoSomethingAsync());
promises.push(DoSomethingAsync());
promises.push(DoSomethingAsync());
var ResultContent = pjs.fiber.runPromise(Promise.all(promises));
res.send(ResultContent);
}
exports.run=sampleAPI;