Last active
June 28, 2017 02:01
-
-
Save iambriansreed/737b8c2803eb50e24cf026584bd401e6 to your computer and use it in GitHub Desktop.
JS Bin// source https://jsbin.com/tekiruy/edit?js,console
This file contains hidden or 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
| '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