3 Object.defineProperty(exports, "__esModule", {
6 exports.default = doWhilst;
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 * The post-check version of [`whilst`]{@link module:ControlFlow.whilst}. To reflect the difference in
24 * the order of operations, the arguments `test` and `iteratee` are switched.
26 * `doWhilst` is to `whilst` as `do while` is to `while` in plain JavaScript.
30 * @memberOf module:ControlFlow
32 * @see [async.whilst]{@link module:ControlFlow.whilst}
33 * @category Control Flow
34 * @param {Function} iteratee - A function which is called each time `test`
35 * passes. The function is passed a `callback(err)`, which must be called once
36 * it has completed with an optional `err` argument. Invoked with (callback).
37 * @param {Function} test - synchronous truth test to perform after each
38 * execution of `iteratee`. Invoked with the non-error callback results of
40 * @param {Function} [callback] - A callback which is called after the test
41 * function has failed and repeated execution of `iteratee` has stopped.
42 * `callback` will be passed an error and any arguments passed to the final
43 * `iteratee`'s callback. Invoked with (err, [results]);
45 function doWhilst(iteratee, test, callback) {
46 callback = (0, _onlyOnce2.default)(callback || _noop2.default);
47 var next = (0, _rest2.default)(function (err, args) {
48 if (err) return callback(err);
49 if (test.apply(this, args)) return iteratee(next);
50 callback.apply(null, [null].concat(args));
54 module.exports = exports['default'];