-
-
Save aponxi/f8207b30d301ce4722788952de2ed593 to your computer and use it in GitHub Desktop.
Promise "loop" using the Bluebird library
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 promiseWhile = function(condition, body) { | |
| var resolver = Promise.defer(); | |
| var loop = function() { | |
| if (!condition()) return resolver.resolve(); | |
| return Promise.cast(body()) | |
| .then(loop) | |
| .catch(resolver.reject); | |
| }; | |
| process.nextTick(loop); | |
| return resolver.promise; | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment