I need to make some consecutive calls to an API until the request limit completes. After each request, something is saved to the db and the next request depends on the values retrieved from the first request, so every request can't be started until the previous one finishes.
A common while loop won't work because it will run all the promises in a parallel way. And promises concatenated after each other will only work for a fixed number of requests.
So, how to do achieve a promises while loop?
Basically what I want:
let remaining = 200;
let start_id = null;
while (remaining > 0) {
// make http request with param start_id
// save results to db
// update 'update' start_id
// update 'remaining' from http header
}