I need to use the for-of loop and need to await till all the async requests from looping the inputArray
array are done and then return the requests
array. How can I make this happen?
const getRequests = async () => {
const bulkEmails = new BulkEmails();
const requests = [];
const inputArray = [];
for (let input of inputArray) {
const response = await getAsyncData(input);
if (response.data) {
bulkEmails.addEmail(..email); // Email added
if (bulkEmails.emails.length > 500) {
// If more than 500 emails in one bulk email object, push object with data to requests array
requests.push({bulkEmails, data: response.data});
bulkEmails = [];
}
}
}
return requests;
}
const requests = await getRequests();
// Loop over all (prepare requests to finally send them