UNPKG

1.7 kBJavaScriptView Raw
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = doUntil;
7
8var _doWhilst = require('./doWhilst');
9
10var _doWhilst2 = _interopRequireDefault(_doWhilst);
11
12var _wrapAsync = require('./internal/wrapAsync');
13
14var _wrapAsync2 = _interopRequireDefault(_wrapAsync);
15
16function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
18/**
19 * Like ['doWhilst']{@link module:ControlFlow.doWhilst}, except the `test` is inverted. Note the
20 * argument ordering differs from `until`.
21 *
22 * @name doUntil
23 * @static
24 * @memberOf module:ControlFlow
25 * @method
26 * @see [async.doWhilst]{@link module:ControlFlow.doWhilst}
27 * @category Control Flow
28 * @param {AsyncFunction} iteratee - An async function which is called each time
29 * `test` fails. Invoked with (callback).
30 * @param {AsyncFunction} test - asynchronous truth test to perform after each
31 * execution of `iteratee`. Invoked with (...args, callback), where `...args` are the
32 * non-error args from the previous callback of `iteratee`
33 * @param {Function} [callback] - A callback which is called after the test
34 * function has passed and repeated execution of `iteratee` has stopped. `callback`
35 * will be passed an error and any arguments passed to the final `iteratee`'s
36 * callback. Invoked with (err, [results]);
37 * @returns {Promise} a promise, if no callback is passed
38 */
39function doUntil(iteratee, test, callback) {
40 const _test = (0, _wrapAsync2.default)(test);
41 return (0, _doWhilst2.default)(iteratee, (...args) => {
42 const cb = args.pop();
43 _test(...args, (err, truth) => cb(err, !truth));
44 }, callback);
45}
46module.exports = exports['default'];
\No newline at end of file