Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verify that the argument to parallel is valid. #421

Merged
merged 1 commit into from
Jan 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3143,6 +3143,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