Skip to content

Instantly share code, notes, and snippets.

@iambriansreed
Last active June 28, 2017 02:01
Show Gist options
  • Select an option

  • Save iambriansreed/737b8c2803eb50e24cf026584bd401e6 to your computer and use it in GitHub Desktop.

Select an option

Save iambriansreed/737b8c2803eb50e24cf026584bd401e6 to your computer and use it in GitHub Desktop.
'use strict';
var promiseList = [function () {
return Promise.resolve(2);
}, promiseGenerator(), promiseGenerator(), promiseGenerator(), promiseGenerator(), promiseGenerator()];
function promiseGenerator() {
return function (val) {
return new Promise(function (resolve, reject) {
resolve(val * 2);
});
};
}
function promiseRecurser(list, val) {
if (!list.length) return val;
var nextPromise = list.shift();
return nextPromise(val).then(function (val) {
return promiseRecurser(list, val);
});
}
promiseRecurser(promiseList).then(function (val) {
console.log('last: ' + val);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment