Bug:Fix file validation issue
[vnfsdk/refrepo.git] / vnfmarket / src / main / webapp / vnfmarket / node_modules / form-data / node_modules / async / during.js
1 'use strict';
2
3 Object.defineProperty(exports, "__esModule", {
4     value: true
5 });
6 exports.default = during;
7
8 var _noop = require('lodash/noop');
9
10 var _noop2 = _interopRequireDefault(_noop);
11
12 var _onlyOnce = require('./internal/onlyOnce');
13
14 var _onlyOnce2 = _interopRequireDefault(_onlyOnce);
15
16 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
18 /**
19  * Like [`whilst`]{@link module:ControlFlow.whilst}, except the `test` is an asynchronous function that
20  * is passed a callback in the form of `function (err, truth)`. If error is
21  * passed to `test` or `fn`, the main callback is immediately called with the
22  * value of the error.
23  *
24  * @name during
25  * @static
26  * @memberOf module:ControlFlow
27  * @method
28  * @see [async.whilst]{@link module:ControlFlow.whilst}
29  * @category Control Flow
30  * @param {Function} test - asynchronous truth test to perform before each
31  * execution of `fn`. Invoked with (callback).
32  * @param {Function} fn - A function which is called each time `test` passes.
33  * The function is passed a `callback(err)`, which must be called once it has
34  * completed with an optional `err` argument. Invoked with (callback).
35  * @param {Function} [callback] - A callback which is called after the test
36  * function has failed and repeated execution of `fn` has stopped. `callback`
37  * will be passed an error, if one occured, otherwise `null`.
38  * @example
39  *
40  * var count = 0;
41  *
42  * async.during(
43  *     function (callback) {
44  *         return callback(null, count < 5);
45  *     },
46  *     function (callback) {
47  *         count++;
48  *         setTimeout(callback, 1000);
49  *     },
50  *     function (err) {
51  *         // 5 seconds have passed
52  *     }
53  * );
54  */
55 function during(test, fn, callback) {
56     callback = (0, _onlyOnce2.default)(callback || _noop2.default);
57
58     function next(err) {
59         if (err) return callback(err);
60         test(check);
61     }
62
63     function check(err, truth) {
64         if (err) return callback(err);
65         if (!truth) return callback(null);
66         fn(next);
67     }
68
69     test(check);
70 }
71 module.exports = exports['default'];