diff options
author | Alexander Early <aearly@fluid.com> | 2015-05-31 20:44:02 -0700 |
---|---|---|
committer | Alexander Early <aearly@fluid.com> | 2015-05-31 20:44:02 -0700 |
commit | 5244f77ad8d7c539f450fc77fc550288780ec323 (patch) | |
tree | f8db321688368a461f1d0b3ca881b07948f35c48 | |
parent | 32b4ce66880d0fae5d26e7d144e1c204ec1e4a57 (diff) | |
download | async-5244f77ad8d7c539f450fc77fc550288780ec323.tar.gz |
added check to queue.push(). Fixes #593
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | lib/async.js | 8 | ||||
-rwxr-xr-x | test/test-async.js | 8 |
3 files changed, 15 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index eabdf28..f6960bc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ Bug Fixes: - Ensure proper conditions when calling `drain()` after pushing an empty data set to a queue (#668) - `each` and family will properly handle an empty array (#578) - `eachSeries` and family will finish if the underlying array is modified during execution (#557) +- `queue` will throw if a non-function is passed to `q.push()` (#593) - Doc fixes (#766) diff --git a/lib/async.js b/lib/async.js index ba90413..fd7a953 100644 --- a/lib/async.js +++ b/lib/async.js @@ -807,6 +807,9 @@ throw new Error('Concurrency must not be zero'); } function _insert(q, data, pos, callback) { + if (callback != null && typeof callback !== "function") { + throw new Error("task callback must be a function"); + } q.started = true; if (!_isArray(data)) { data = [data]; @@ -940,9 +943,10 @@ } function _insert(q, data, priority, callback) { - if (!q.started){ - q.started = true; + if (callback != null && typeof callback !== "function") { + throw new Error("task callback must be a function"); } + q.started = true; if (!_isArray(data)) { data = [data]; } diff --git a/test/test-async.js b/test/test-async.js index 2f51443..bdb8147 100755 --- a/test/test-async.js +++ b/test/test-async.js @@ -2848,6 +2848,14 @@ exports['queue'] = { }, 800); }, +'push with non-function': function (test) { + var q = async.queue(function () {}, 1); + test.throws(function () { + q.push({}, 1); + }); + test.done(); +}, + 'unshift': function (test) { var queue_order = []; |