Skip to content

Instantly share code, notes, and snippets.

@LB-Digital
Created September 11, 2018 19:46
Show Gist options
  • Save LB-Digital/39d254578178c17b7884a2cd0ca91b1f to your computer and use it in GitHub Desktop.
Save LB-Digital/39d254578178c17b7884a2cd0ca91b1f to your computer and use it in GitHub Desktop.
Loop through items, awaiting a promise return for each item.
function myFunc(items){
var fn = function addSomethingToItem(item){
return new Promise(resolve => {
myFirstActionFunc()
.then( response =>{
item.value = response;
resolve(item);
})
.catch(err => reject(err));
});
};
var actions = items.map(fn);
var results = Promise.all(actions);
return new Promise( (resolve,reject) =>{
results.then(data =>{
return resolve(data);
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment