Skip to content

Commit

Permalink
PR fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
hargasinski committed Jun 22, 2017
1 parent 39b20e6 commit a0ffde8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
3 changes: 2 additions & 1 deletion lib/concatLimit.js
Expand Up @@ -3,6 +3,8 @@ import wrapAsync from './internal/wrapAsync';
import slice from './internal/slice';
import mapLimit from './mapLimit';

var _concat = Array.prototype.concat;

/**
* The same as [`concat`]{@link module:Collections.concat} but runs a maximum of `limit` async operations at a time.
*
Expand Down Expand Up @@ -31,7 +33,6 @@ export default function(coll, limit, iteratee, callback) {
});
}, function(err, mapResults) {
var result = [];
var _concat = Array.prototype.concat;
for (var i = 0; i < mapResults.length; i++) {
if (mapResults[i]) {
result = _concat.apply(result, mapResults[i]);
Expand Down
26 changes: 18 additions & 8 deletions mocha_test/concat.js
Expand Up @@ -307,28 +307,38 @@ describe('concat', function() {
it('does not continue replenishing after error', function(done) {
var started = 0;
var arr = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
var delay = 10;
var limit = 3;
var maxTime = 10 * arr.length;
var step = 0;
var maxSteps = arr.length;

async.concatLimit(arr, limit, function(val, next) {
started++;
if (started === 3) {
return next(new Error('fail'));
}

setTimeout(function() {
async.setImmediate(function() {
next();
}, delay);
});
}, function(err, result) {
expect(err).to.not.eql(null);
expect(result).to.be.an('array').that.is.empty;
});

setTimeout(function() {
expect(started).to.equal(3);
done();
}, maxTime);
// wait `maxSteps` event loop cycles before calling done to ensure
// the iteratee is not called on more items in arr.
function waitCycle() {
step++;
if (step >= maxSteps) {
expect(started).to.equal(3);
done();
return;
} else {
async.setImmediate(waitCycle);
}
}

async.setImmediate(waitCycle);
});
});

Expand Down

0 comments on commit a0ffde8

Please sign in to comment.