Created
September 17, 2017 12:03
-
-
Save AnasAboreeda/595d2dec1911ac0295bd2dd5f08c60cd to your computer and use it in GitHub Desktop.
[While Promise] A while promise that returns a 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
// Promise while that return promise | |
var P = require('bluebird'); | |
var promiseWhile = P.method(function(condition, action) { | |
if (!condition()) {return;} | |
return action().then(promiseWhile.bind(null, condition, action)); | |
}); | |
/* | |
Usage: | |
*/ | |
var condition = true; | |
promiseWhile(function() { return condition; }, function() { | |
// some promise logic that will set condition to false at some point; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment