| 1 | 'use strict';
|
|---|
| 2 |
|
|---|
| 3 | Object.defineProperty(exports, "__esModule", {
|
|---|
| 4 | value: true
|
|---|
| 5 | });
|
|---|
| 6 | exports.default = doUntil;
|
|---|
| 7 |
|
|---|
| 8 | var _doWhilst = require('./doWhilst.js');
|
|---|
| 9 |
|
|---|
| 10 | var _doWhilst2 = _interopRequireDefault(_doWhilst);
|
|---|
| 11 |
|
|---|
| 12 | var _wrapAsync = require('./internal/wrapAsync.js');
|
|---|
| 13 |
|
|---|
| 14 | var _wrapAsync2 = _interopRequireDefault(_wrapAsync);
|
|---|
| 15 |
|
|---|
| 16 | function _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 | */
|
|---|
| 39 | function 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 | }
|
|---|
| 46 | module.exports = exports.default; |
|---|