You could use Promises
for all requestItems {
http.post(url, body).toPromise().catch(error => {
// This request failed.
})
}
or if you want to wait for all to finish, you can collect the promises to an array and then use
Promise.all(promises)
.catch(error => ...)
.then(results => ...);
as can be seen in Handling errors in Promise.all
Edit:
You can use Promise.all this way:
// Create an array of your promises
const promises = [...];
const resolvedPromises = [];
promises.forEach(promise => {
// Collect resolved promises - you may return some values from then and catch
resolvedPromises.push(promise
.then(result => 'OK')
.catch(error => 'Error')
);
});
Promise.all(resolvedPromises).then(results => {
// results contains values returned from then/catch before
console.log('Finished');
})