Created
September 11, 2017 14:08
-
-
Save thcolin/f6f7f4a5b4b66a8bc8e54adcd64fa775 to your computer and use it in GitHub Desktop.
Recursive Promise delayed
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
| var promise = Promise.resolve() | |
| var values = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] | |
| values.forEach(function(id) { | |
| promise = promise.then(function() { | |
| return new Promise(function(resolve, reject) { | |
| setTimeout(function() { | |
| resolve(id) | |
| }, 2000) | |
| }) | |
| }).then(function(id) { | |
| console.log('VALUE', id) | |
| }) | |
| }) | |
| promise.then(function() { | |
| console.log('FINISH') | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment