I am looking for something similar to Promise.allthat that will continue to resolve promises at the same time even if one or more of the promises rejects or gives an error. Each request is independent of another request.
Close to what I want - see comments
function fetchRequest (request) {
return new Promise(function (resolve, reject) {
fetch(request)
.then(function(response) {
return response.text();
}).then(function (responseXML) {
resolve(responseXML);
}).catch(function (err) {
reject(new Error(err));
}
}
function promiseRequests (requests) {
var result = Promise.resolve();
for (var i = 0; i < requests.length; i++) {
result = fetchRequest(requests[i])
}
resolve(result);
}
promiseRequests(['url1.com', 'url2.com']).then(function (data) {
console.log('All requests finished');
});
I managed to use Promise.allfetchRequest together with only the resolving promise, and this leads to the expected result (an array of results and undefined), but I feel that this is the wrong way to do something, It also removes my ability to use abandoned errors.
Works, but seems to be misusing permission
function fetchRequest (request) {
return new Promise(function (resolve, reject) {
fetch(request)
.then(function(response) {
return response.text();
}).then(function (responseXML) {
resolve(responseXML);
}).catch(function (err) {
resolve();
}
}
Promise.all([fetchRequest('url1.com'), fetchRequest('url2.com')]).then(function (data) {
console.log('All requests finished', data);
});
Please respond only to es6 API support.