diff --git a/lib/index.js b/lib/index.js index 50bfeb7..50b990a 100755 --- a/lib/index.js +++ b/lib/index.js @@ -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 diff --git a/test/test.js b/test/test.js index b227477..b72295f 100755 --- a/test/test.js +++ b/test/test.js @@ -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();