Created
September 11, 2018 19:46
-
-
Save LB-Digital/39d254578178c17b7884a2cd0ca91b1f to your computer and use it in GitHub Desktop.
Loop through items, awaiting a promise return for each item.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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