3 Object.defineProperty(exports, "__esModule", {
6 exports.default = forever;
8 var _noop = require('lodash/noop');
10 var _noop2 = _interopRequireDefault(_noop);
12 var _onlyOnce = require('./internal/onlyOnce');
14 var _onlyOnce2 = _interopRequireDefault(_onlyOnce);
16 var _ensureAsync = require('./ensureAsync');
18 var _ensureAsync2 = _interopRequireDefault(_ensureAsync);
20 function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
23 * Calls the asynchronous function `fn` with a callback parameter that allows it
24 * to call itself again, in series, indefinitely.
26 * If an error is passed to the
27 * callback then `errback` is called with the error, and execution stops,
28 * otherwise it will never be called.
32 * @memberOf module:ControlFlow
34 * @category Control Flow
35 * @param {Function} fn - a function to call repeatedly. Invoked with (next).
36 * @param {Function} [errback] - when `fn` passes an error to it's callback,
37 * this function will be called, and execution stops. Invoked with (err).
42 * // next is suitable for passing to things that need a callback(err [, whatever]);
43 * // it will result in this function being called again.
46 * // if next is called with a value in its first parameter, it will appear
47 * // in here as 'err', and execution will stop.
51 function forever(fn, errback) {
52 var done = (0, _onlyOnce2.default)(errback || _noop2.default);
53 var task = (0, _ensureAsync2.default)(fn);
56 if (err) return done(err);
61 module.exports = exports['default'];