Guest User

Untitled

a guest
Aug 20th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. // Set global-ish variables that can be referenced from multiple functions
  2. var storageArray = [];
  3. var numberOfPromiseCalls = 10;
  4. var promiseCallsCount = 0;
  5.  
  6. // Setup promise wrapper
  7. function promiseWrapper(inputParams){
  8. return new Promise(function(resolve, reject) {
  9. // awesome stuff at work here using inputParams
  10. resolve(desiredOutput);
  11. }
  12. })
  13.  
  14. // call promise 10 times
  15. for(i=0;i<numberOfPromiseCalls;i++){
  16.  
  17. // actual promise call
  18. promiseWrapper(inputParams[i]).then(function (desiredOutput) {
  19.  
  20. // push resolve to storage array
  21. storageArray.push(resolve);
  22.  
  23. // test if this resolve is the "last" resolve of all the promises we called
  24. promiseCallsCount++;
  25. if(promiseCallsCount == numberOfPromiseCalls){
  26.  
  27. // ************************
  28. // call a function that can work with the final storageArray
  29. // ************************
  30.  
  31. }
  32. })
  33. }
Add Comment
Please, Sign In to add comment