How do I make the last console.log line of the code snippet execute only after ALL the updateInkLevel functions finish executing?
for (let i = 0; i < activeDevices.length; i++) {
updateInkLevel(accessToken, deviceId, logIndex)
await new Promise((r) => setTimeout(r, 500)) // add a small sleep delay
}
console.log("everything completed")
updateInkLevel is an async function, returning a promise. I was thinking of using Promise.all, but that would run each iteration in parallel, which is not I want here. Here, I'm firing each iteration sequentially one at a time, with a small sleep delay before firing the next call.
I'm looking for something like Promise.all, but without running in parallel.
References, Is Node.js native Promise.all processing in parallel or sequentially?