3 Object.defineProperty(exports, "__esModule", {
6 exports.default = whilst;
8 var _noop = require('lodash/noop');
10 var _noop2 = _interopRequireDefault(_noop);
12 var _rest = require('./internal/rest');
14 var _rest2 = _interopRequireDefault(_rest);
16 var _onlyOnce = require('./internal/onlyOnce');
18 var _onlyOnce2 = _interopRequireDefault(_onlyOnce);
20 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23 * Repeatedly call `iteratee`, while `test` returns `true`. Calls `callback` when
24 * stopped, or an error occurs.
28 * @memberOf module:ControlFlow
30 * @category Control Flow
31 * @param {Function} test - synchronous truth test to perform before each
32 * execution of `iteratee`. Invoked with ().
33 * @param {Function} iteratee - A function which is called each time `test` passes.
34 * The function is passed a `callback(err)`, which must be called once it has
35 * completed with an optional `err` argument. Invoked with (callback).
36 * @param {Function} [callback] - A callback which is called after the test
37 * function has failed and repeated execution of `iteratee` has stopped. `callback`
38 * will be passed an error and any arguments passed to the final `iteratee`'s
39 * callback. Invoked with (err, [results]);
45 * function() { return count < 5; },
46 * function(callback) {
48 * setTimeout(function() {
49 * callback(null, count);
53 * // 5 seconds have passed, n = 5
57 function whilst(test, iteratee, callback) {
58 callback = (0, _onlyOnce2.default)(callback || _noop2.default);
59 if (!test()) return callback(null);
60 var next = (0, _rest2.default)(function (err, args) {
61 if (err) return callback(err);
62 if (test()) return iteratee(next);
63 callback.apply(null, [null].concat(args));
67 module.exports = exports['default'];