Skip to content

Instantly share code, notes, and snippets.

@tujlaky
Created June 15, 2015 06:28
Show Gist options
  • Save tujlaky/64e3967768b98dd5f9ff to your computer and use it in GitHub Desktop.
Save tujlaky/64e3967768b98dd5f9ff to your computer and use it in GitHub Desktop.
recursive promise with array
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