Created
June 15, 2015 06:01
-
-
Save tujlaky/e9cc29e7c12cc3bd0a18 to your computer and use it in GitHub Desktop.
recursive promise
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 ) { | |
console.log('asd'); | |
return testRecursive(count-1).then(function(c) { | |
resolve(c); | |
}); | |
} else { | |
resolve(count); | |
} | |
}); | |
}; | |
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