Skip to content

Commit

Permalink
Merge pull request #421 from vqvu/parallel-error-checking
Browse files Browse the repository at this point in the history
Verify that the argument to parallel is valid.
  • Loading branch information
svozza committed Jan 1, 2016
2 parents ddbd3d5 + 5f08426 commit 35735a9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3159,6 +3159,14 @@ Stream.prototype.parallel = function (n) {
var ended = false;
var reading_source = false;

if (typeof n !== 'number') {
throw new Error('Must specify a number to parallel().');
}

if (n <= 0) {
throw new Error('The parallelism factor must be positive');
}

return _(function (push, next) {
if (running.length < n && !ended && !reading_source) {
// get another stream if not already waiting for one
Expand Down
16 changes: 16 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5317,6 +5317,22 @@ exports['parallel - parallel should not drop data if paused (issue #328)'] = fun
});
};

exports['parallel - should throw if arg is not a number (issue #420)'] = function (test) {
test.expect(1);
test.throws(function () {
_([]).parallel();
});
test.done();
};

exports['parallel - should throw if arg is not positive'] = function (test) {
test.expect(1);
test.throws(function () {
_([]).parallel(-1);
});
test.done();
};

exports['throttle'] = {
setUp: function (callback) {
this.clock = sinon.useFakeTimers();
Expand Down

0 comments on commit 35735a9

Please sign in to comment.