source: trip-planner-front/node_modules/async/during.js@ 571e0df

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

initial commit

  • Property mode set to 100644
File size: 2.1 KB
RevLine 
[6a3a178]1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = during;
7
8var _noop = require('lodash/noop');
9
10var _noop2 = _interopRequireDefault(_noop);
11
12var _onlyOnce = require('./internal/onlyOnce');
13
14var _onlyOnce2 = _interopRequireDefault(_onlyOnce);
15
16var _wrapAsync = require('./internal/wrapAsync');
17
18var _wrapAsync2 = _interopRequireDefault(_wrapAsync);
19
20function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
22/**
23 * Like [`whilst`]{@link module:ControlFlow.whilst}, except the `test` is an asynchronous function that
24 * is passed a callback in the form of `function (err, truth)`. If error is
25 * passed to `test` or `fn`, the main callback is immediately called with the
26 * value of the error.
27 *
28 * @name during
29 * @static
30 * @memberOf module:ControlFlow
31 * @method
32 * @see [async.whilst]{@link module:ControlFlow.whilst}
33 * @category Control Flow
34 * @param {AsyncFunction} test - asynchronous truth test to perform before each
35 * execution of `fn`. Invoked with (callback).
36 * @param {AsyncFunction} fn - An async function which is called each time
37 * `test` passes. Invoked with (callback).
38 * @param {Function} [callback] - A callback which is called after the test
39 * function has failed and repeated execution of `fn` has stopped. `callback`
40 * will be passed an error, if one occurred, otherwise `null`.
41 * @example
42 *
43 * var count = 0;
44 *
45 * async.during(
46 * function (callback) {
47 * return callback(null, count < 5);
48 * },
49 * function (callback) {
50 * count++;
51 * setTimeout(callback, 1000);
52 * },
53 * function (err) {
54 * // 5 seconds have passed
55 * }
56 * );
57 */
58function during(test, fn, callback) {
59 callback = (0, _onlyOnce2.default)(callback || _noop2.default);
60 var _fn = (0, _wrapAsync2.default)(fn);
61 var _test = (0, _wrapAsync2.default)(test);
62
63 function next(err) {
64 if (err) return callback(err);
65 _test(check);
66 }
67
68 function check(err, truth) {
69 if (err) return callback(err);
70 if (!truth) return callback(null);
71 _fn(next);
72 }
73
74 _test(check);
75}
76module.exports = exports['default'];
Note: See TracBrowser for help on using the repository browser.