Skip to content

Commit

Permalink
ISSUE-9 - fixed flow control and added a test to confirm
Browse files Browse the repository at this point in the history
  • Loading branch information
jhaugh42 committed Jun 29, 2016
1 parent 9575865 commit 8dc2a59
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/concurrent.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module.exports = Concurrent = {
concurrent: function(functions, callback) {
if (functions.length === 0) {
process.nextTick(callback.bind(null, null, []));
return;
}

var state = {
Expand Down
8 changes: 8 additions & 0 deletions test/unit/concurrent.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,19 @@ describe('concurrent - unit tests', function() {

describe('concurrent - entry point - empty input', function() {
var tasks = [];
var forEachStub;
before(function() {
mapConcurrentCallbackBindStub = sinon.stub(Concurrent._concurrentCallback, 'bind').returns(boundConcurrentCallback);
forEachStub = sinon.stub(Array.prototype, 'forEach');
});

after(function() {
Concurrent._concurrentCallback.bind.restore();
Array.prototype.forEach.restore();
});

beforeEach(function() {
forEachStub.reset();
mapConcurrentCallbackBindStub.reset();
Concurrent.concurrent(tasks, callbackSpy);
});
Expand All @@ -127,6 +131,10 @@ describe('concurrent - unit tests', function() {
boundCallbackSpy
]);
});

it('should not call forEach when the input is an empty array', function() {
expect(forEachStub.callCount).to.equal(0);
});
});

describe('concurrent - callback', function() {
Expand Down

0 comments on commit 8dc2a59

Please sign in to comment.