I've been trying to use a batched array and fire requests sequentially using Promise.all
and a map function:
const slowAsync = (i) => {
return setTimeout(() => {
return Promise.resolve(i);
}, 1000)
}
const batchedIds = [[1,2], [3,4], [5,6]];
batchedIds.map(async batch => {
const response = await Promise.all(batch.map(id => {
return slowAsync(id);
}));
console.log(response);
})
Right now the console logs everything at once
//after 1 second
[1, 2]
[3, 4]
[5, 6]
but I want it to log each resolve of the promise with 1 second difference
//after 1 second
[1, 2]
//after 1 second
[3, 4]
//after 1 second
[5, 6]
Is it possible to do this without recursion or libraries and by using a map function?