Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Set global-ish variables that can be referenced from multiple functions
- var storageArray = [];
- var numberOfPromiseCalls = 10;
- var promiseCallsCount = 0;
- // Setup promise wrapper
- function promiseWrapper(inputParams){
- return new Promise(function(resolve, reject) {
- // awesome stuff at work here using inputParams
- resolve(desiredOutput);
- }
- })
- // call promise 10 times
- for(i=0;i<numberOfPromiseCalls;i++){
- // actual promise call
- promiseWrapper(inputParams[i]).then(function (desiredOutput) {
- // push resolve to storage array
- storageArray.push(resolve);
- // test if this resolve is the "last" resolve of all the promises we called
- promiseCallsCount++;
- if(promiseCallsCount == numberOfPromiseCalls){
- // ************************
- // call a function that can work with the final storageArray
- // ************************
- }
- })
- }
Add Comment
Please, Sign In to add comment