source: trip-planner-front/node_modules/async/forever.js@ 76712b2

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

initial commit

  • Property mode set to 100644
File size: 1.9 KB
Line 
1'use strict';
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.default = forever;
7
8var _noop = require('lodash/noop');
9
10var _noop2 = _interopRequireDefault(_noop);
11
12var _onlyOnce = require('./internal/onlyOnce');
13
14var _onlyOnce2 = _interopRequireDefault(_onlyOnce);
15
16var _ensureAsync = require('./ensureAsync');
17
18var _ensureAsync2 = _interopRequireDefault(_ensureAsync);
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 * Calls the asynchronous function `fn` with a callback parameter that allows it
28 * to call itself again, in series, indefinitely.
29
30 * If an error is passed to the callback then `errback` is called with the
31 * error, and execution stops, otherwise it will never be called.
32 *
33 * @name forever
34 * @static
35 * @memberOf module:ControlFlow
36 * @method
37 * @category Control Flow
38 * @param {AsyncFunction} fn - an async function to call repeatedly.
39 * Invoked with (next).
40 * @param {Function} [errback] - when `fn` passes an error to it's callback,
41 * this function will be called, and execution stops. Invoked with (err).
42 * @example
43 *
44 * async.forever(
45 * function(next) {
46 * // next is suitable for passing to things that need a callback(err [, whatever]);
47 * // it will result in this function being called again.
48 * },
49 * function(err) {
50 * // if next is called with a value in its first parameter, it will appear
51 * // in here as 'err', and execution will stop.
52 * }
53 * );
54 */
55function forever(fn, errback) {
56 var done = (0, _onlyOnce2.default)(errback || _noop2.default);
57 var task = (0, _wrapAsync2.default)((0, _ensureAsync2.default)(fn));
58
59 function next(err) {
60 if (err) return done(err);
61 task(next);
62 }
63 next();
64}
65module.exports = exports['default'];
Note: See TracBrowser for help on using the repository browser.