-
-
Save disco0/e2dc4a7ea26c7fc5eba347a16d8798ee to your computer and use it in GitHub Desktop.
Asynchronous while loop for ES6 Promises.
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
function asyncWhile(condition, action, ctx) { | |
var whilst = function(data) { | |
return condition.call(ctx, data) ? | |
Promise.resolve(action.call(ctx, data)).then(whilst) : | |
data; | |
} | |
return whilst(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment