"use strict"; const Promise = require("bluebird"); module.exports = function asyncWhile(predicate, body) { function doTick() { return Promise.try(() => { return predicate(); }).then((shouldRun) => { if (shouldRun) { return Promise.try(() => { return body(); }).then(() => { return doTick(); }); } }); } return doTick(); };