source: trip-planner-front/node_modules/async/whilst.js@ 6a3a178

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

initial commit

  • Property mode set to 100644
File size: 2.1 KB
Line 
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = whilst;
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 * Repeatedly call `iteratee`, while `test` returns `true`. Calls `callback` when
28 * stopped, or an error occurs.
29 *
30 * @name whilst
31 * @static
32 * @memberOf module:ControlFlow
33 * @method
34 * @category Control Flow
35 * @param {Function} test - synchronous truth test to perform before each
36 * execution of `iteratee`. Invoked with ().
37 * @param {AsyncFunction} iteratee - An async function which is called each time
38 * `test` passes. Invoked with (callback).
39 * @param {Function} [callback] - A callback which is called after the test
40 * function has failed and repeated execution of `iteratee` has stopped. `callback`
41 * will be passed an error and any arguments passed to the final `iteratee`'s
42 * callback. Invoked with (err, [results]);
43 * @returns undefined
44 * @example
45 *
46 * var count = 0;
47 * async.whilst(
48 * function() { return count < 5; },
49 * function(callback) {
50 * count++;
51 * setTimeout(function() {
52 * callback(null, count);
53 * }, 1000);
54 * },
55 * function (err, n) {
56 * // 5 seconds have passed, n = 5
57 * }
58 * );
59 */
60function whilst(test, iteratee, callback) {
61 callback = (0, _onlyOnce2.default)(callback || _noop2.default);
62 var _iteratee = (0, _wrapAsync2.default)(iteratee);
63 if (!test()) return callback(null);
64 var next = function (err /*, ...args*/) {
65 if (err) return callback(err);
66 if (test()) return _iteratee(next);
67 var args = (0, _slice2.default)(arguments, 1);
68 callback.apply(null, [null].concat(args));
69 };
70 _iteratee(next);
71}
72module.exports = exports['default'];
Note: See TracBrowser for help on using the repository browser.