Created
June 15, 2015 06:28
-
-
Save tujlaky/64e3967768b98dd5f9ff to your computer and use it in GitHub Desktop.
recursive promise with array
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 = require('bluebird'); | |
var testRecursive = function(count) { | |
return new Promise(function(resolve, reject) { | |
if ( count > 0 ) { | |
return testRecursive(count-1) | |
.then(function(numbers) { | |
numbers.push(count); | |
resolve(numbers); | |
}); | |
} else { | |
var numbers = []; | |
numbers.push(count); | |
resolve(numbers); | |
} | |
}); | |
}; | |
testRecursive(5) | |
.then(function(count) { | |
console.log('Resolved: ' + count); | |
}) | |
.catch(function(err) { | |
throw err; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment