wallet-core/node_modules/async/internal/createTester.js

50 lines
1.5 KiB
JavaScript
Raw Normal View History

2016-10-10 03:43:44 +02:00
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = _createTester;
var _noop = require('lodash/noop');
var _noop2 = _interopRequireDefault(_noop);
2016-11-03 01:33:53 +01:00
var _breakLoop = require('./breakLoop');
var _breakLoop2 = _interopRequireDefault(_breakLoop);
2016-10-10 03:43:44 +02:00
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
function _createTester(eachfn, check, getResult) {
return function (arr, limit, iteratee, cb) {
2016-11-03 01:33:53 +01:00
function done() {
2016-10-10 03:43:44 +02:00
if (cb) {
2016-11-03 01:33:53 +01:00
cb(null, getResult(false));
2016-10-10 03:43:44 +02:00
}
}
function wrappedIteratee(x, _, callback) {
if (!cb) return callback();
iteratee(x, function (err, v) {
2016-11-03 01:33:53 +01:00
// Check cb as another iteratee may have resolved with a
// value or error since we started this iteratee
if (cb && (err || check(v))) {
if (err) cb(err);else cb(err, getResult(true, x));
cb = iteratee = false;
callback(err, _breakLoop2.default);
} else {
callback();
2016-10-10 03:43:44 +02:00
}
});
}
if (arguments.length > 3) {
cb = cb || _noop2.default;
eachfn(arr, limit, wrappedIteratee, done);
} else {
cb = iteratee;
cb = cb || _noop2.default;
iteratee = limit;
eachfn(arr, wrappedIteratee, done);
}
};
}
module.exports = exports['default'];