source: trip-planner-front/node_modules/async/doWhilst.js@ 6c1585f

Last change on this file since 6c1585f was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.0 KB
Line 
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = doWhilst;
7
8var _noop = require('lodash/noop');
9
10var _noop2 = _interopRequireDefault(_noop);
11
12var _slice = require('./internal/slice');
13
14var _slice2 = _interopRequireDefault(_slice);
15
16var _onlyOnce = require('./internal/onlyOnce');
17
18var _onlyOnce2 = _interopRequireDefault(_onlyOnce);
19
20var _wrapAsync = require('./internal/wrapAsync');
21
22var _wrapAsync2 = _interopRequireDefault(_wrapAsync);
23
24function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
26/**
27 * The post-check version of [`whilst`]{@link module:ControlFlow.whilst}. To reflect the difference in
28 * the order of operations, the arguments `test` and `iteratee` are switched.
29 *
30 * `doWhilst` is to `whilst` as `do while` is to `while` in plain JavaScript.
31 *
32 * @name doWhilst
33 * @static
34 * @memberOf module:ControlFlow
35 * @method
36 * @see [async.whilst]{@link module:ControlFlow.whilst}
37 * @category Control Flow
38 * @param {AsyncFunction} iteratee - A function which is called each time `test`
39 * passes. Invoked with (callback).
40 * @param {Function} test - synchronous truth test to perform after each
41 * execution of `iteratee`. Invoked with any non-error callback results of
42 * `iteratee`.
43 * @param {Function} [callback] - A callback which is called after the test
44 * function has failed and repeated execution of `iteratee` has stopped.
45 * `callback` will be passed an error and any arguments passed to the final
46 * `iteratee`'s callback. Invoked with (err, [results]);
47 */
48function doWhilst(iteratee, test, callback) {
49 callback = (0, _onlyOnce2.default)(callback || _noop2.default);
50 var _iteratee = (0, _wrapAsync2.default)(iteratee);
51 var next = function (err /*, ...args*/) {
52 if (err) return callback(err);
53 var args = (0, _slice2.default)(arguments, 1);
54 if (test.apply(this, args)) return _iteratee(next);
55 callback.apply(null, [null].concat(args));
56 };
57 _iteratee(next);
58}
59module.exports = exports['default'];
Note: See TracBrowser for help on using the repository browser.