3 Object.defineProperty(exports, "__esModule", {
6 exports.default = doDuring;
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 [`during`]{@link module:ControlFlow.during}. To reflect the difference in
24 * the order of operations, the arguments `test` and `fn` are switched.
26 * Also a version of [`doWhilst`]{@link module:ControlFlow.doWhilst} with asynchronous `test` function.
29 * @memberOf module:ControlFlow
31 * @see [async.during]{@link module:ControlFlow.during}
32 * @category Control Flow
33 * @param {Function} fn - 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} test - asynchronous truth test to perform before each
37 * execution of `fn`. Invoked with (...args, callback), where `...args` are the
38 * non-error args from the previous callback of `fn`.
39 * @param {Function} [callback] - A callback which is called after the test
40 * function has failed and repeated execution of `fn` has stopped. `callback`
41 * will be passed an error if one occured, otherwise `null`.
43 function doDuring(fn, test, callback) {
44 callback = (0, _onlyOnce2.default)(callback || _noop2.default);
46 var next = (0, _rest2.default)(function (err, args) {
47 if (err) return callback(err);
49 test.apply(this, args);
52 function check(err, truth) {
53 if (err) return callback(err);
54 if (!truth) return callback(null);
60 module.exports = exports['default'];