Sha256: 01952f69d4f257f9716d835f36592b6277aecf174510ab9c88297dba4406cb6b

Contents?: true

Size: 1.87 KB

Versions: 22

Compression:

Stored size: 1.87 KB

Contents

'use strict';

Object.defineProperty(exports, "__esModule", {
    value: true
});
exports.default = _eachOfLimit;

var _noop = require('lodash/noop');

var _noop2 = _interopRequireDefault(_noop);

var _once = require('./once');

var _once2 = _interopRequireDefault(_once);

var _iterator = require('./iterator');

var _iterator2 = _interopRequireDefault(_iterator);

var _onlyOnce = require('./onlyOnce');

var _onlyOnce2 = _interopRequireDefault(_onlyOnce);

var _breakLoop = require('./breakLoop');

var _breakLoop2 = _interopRequireDefault(_breakLoop);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _eachOfLimit(limit) {
    return function (obj, iteratee, callback) {
        callback = (0, _once2.default)(callback || _noop2.default);
        if (limit <= 0 || !obj) {
            return callback(null);
        }
        var nextElem = (0, _iterator2.default)(obj);
        var done = false;
        var running = 0;

        function iterateeCallback(err, value) {
            running -= 1;
            if (err) {
                done = true;
                callback(err);
            } else if (value === _breakLoop2.default || done && running <= 0) {
                done = true;
                return callback(null);
            } else {
                replenish();
            }
        }

        function replenish() {
            while (running < limit && !done) {
                var elem = nextElem();
                if (elem === null) {
                    done = true;
                    if (running <= 0) {
                        callback(null);
                    }
                    return;
                }
                running += 1;
                iteratee(elem.value, elem.key, (0, _onlyOnce2.default)(iterateeCallback));
            }
        }

        replenish();
    };
}
module.exports = exports['default'];

Version data entries

22 entries across 22 versions & 4 rubygems

Version Path
ela-4.1.6 node_modules/async/internal/eachOfLimit.js
ela-4.1.5 node_modules/async/internal/eachOfLimit.js
ela-4.1.4 node_modules/async/internal/eachOfLimit.js
ela-4.1.3 node_modules/async/internal/eachOfLimit.js
ela-4.1.2 node_modules/async/internal/eachOfLimit.js
ela-4.1.1 node_modules/async/internal/eachOfLimit.js
ela-4.1.0 node_modules/async/internal/eachOfLimit.js
cortex-0.1.3 spec/dummy/node_modules/async/internal/eachOfLimit.js
ela-4.0.0 node_modules/async/internal/eachOfLimit.js
ela-3.4.3 node_modules/async/internal/eachOfLimit.js
ela-3.4.2 node_modules/async/internal/eachOfLimit.js
ela-3.4.0 node_modules/async/internal/eachOfLimit.js
ela-3.3.1 node_modules/async/internal/eachOfLimit.js
dragonfly_puppeteer-0.1.0 node_modules/yeoman-generator/node_modules/async/internal/eachOfLimit.js
ela-3.3.0 node_modules/async/internal/eachOfLimit.js
ela-3.2.0 node_modules/async/internal/eachOfLimit.js
ela-3.1.1 node_modules/async/internal/eachOfLimit.js
ela-3.1.0 node_modules/async/internal/eachOfLimit.js
ela-3.0.0 node_modules/async/internal/eachOfLimit.js
ela-2.0.0 node_modules/async/internal/eachOfLimit.js