I am trying to run a number of promises in parallels in a batch but it starts the next batch before I have finished processing the first batch the code works when I use simple timeout promises. Can any one help give me a quick bit of help ?
await asyncFunctionsInBatches.reduce(async (previousBatch, currentBatch, index) => {
await previousBatch;
console.time(`batch ${index}`);
console.log(`Processing batch ${index}...`);
const currentBatchPromises = currentBatch.map(async (row) =>
await sqlFetch(queryDate, queryDate1, username, password, row)
);
await Promise.all(currentBatchPromises);
console.timeEnd(`batch ${index}`);
}, Promise.resolve());
}
This is the promise I am using
const sqlFetch = async (
queryDate,
queryDate1,
username,
password,
rowNumber
) => {
( await createUnixSocketPool(username, password)).query(
fetchQuery.sql,
[queryDate, queryDate1, rowNumber],
async function (err, result) {
if (err) {
console.log(err);
}
console.log(result)
return publishMessage(result).catch(console.error);
}
);
};