diff options
author | Alexander Early <alexander.early@gmail.com> | 2016-06-07 18:32:02 -0700 |
---|---|---|
committer | Alexander Early <alexander.early@gmail.com> | 2016-06-07 18:32:02 -0700 |
commit | 428a3004417c1c456dceecc1ba1c68afe24122fc (patch) | |
tree | 07b74085c7e31740909e24ad2f35f5f239cc2ab9 | |
parent | 6932085d7ca452e8c081ea709d8994fcb0246e27 (diff) | |
download | async-428a3004417c1c456dceecc1ba1c68afe24122fc.tar.gz |
fix new lint errors
39 files changed, 497 insertions, 454 deletions
@@ -36,7 +36,7 @@ "last" ], "semi": 0, - "no-eq-null": 2, + "no-eq-null": 0, "no-unused-expressions": 0, "no-loop-func": 2, "dot-notation": 0, diff --git a/lib/auto.js b/lib/auto.js index 6821e12..bb8ee87 100644 --- a/lib/auto.js +++ b/lib/auto.js @@ -46,6 +46,7 @@ import onlyOnce from './internal/onlyOnce'; * pass an error to their callback. Results are always returned; however, if an * error occurs, no further `tasks` will be performed, and the results object * will only contain partial results. Invoked with (err, results). + * @returns undefined * @example * * async.auto({ diff --git a/lib/compose.js b/lib/compose.js index 441d5ab..227c2ea 100644 --- a/lib/compose.js +++ b/lib/compose.js @@ -15,6 +15,8 @@ var reverse = Array.prototype.reverse; * @memberOf async * @category Control Flow * @param {...Function} functions - the asynchronous functions to compose + * @returns {Function} an asynchronous function that is the composed + * asynchronous `functions` * @example * * function add1(n, callback) { diff --git a/lib/doDuring.js b/lib/doDuring.js index 21560a5..e018fe4 100644 --- a/lib/doDuring.js +++ b/lib/doDuring.js @@ -20,11 +20,11 @@ import during from './during'; * will be passed an error and any arguments passed to the final `fn`'s * callback. Invoked with (err, [results]); */ -export default function doDuring(iteratee, test, cb) { +export default function doDuring(fn, test, callback) { var calls = 0; during(function(next) { if (calls++ < 1) return next(null, true); test.apply(this, arguments); - }, iteratee, cb); + }, fn, callback); } diff --git a/lib/doUntil.js b/lib/doUntil.js index d823135..01f114c 100644 --- a/lib/doUntil.js +++ b/lib/doUntil.js @@ -19,8 +19,8 @@ import doWhilst from './doWhilst'; * will be passed an error and any arguments passed to the final `fn`'s * callback. Invoked with (err, [results]); */ -export default function doUntil(iteratee, test, cb) { - return doWhilst(iteratee, function() { +export default function doUntil(fn, test, callback) { + doWhilst(fn, function() { return !test.apply(this, arguments); - }, cb); + }, callback); } diff --git a/lib/doWhilst.js b/lib/doWhilst.js index c23fe8d..96c4664 100644 --- a/lib/doWhilst.js +++ b/lib/doWhilst.js @@ -22,9 +22,9 @@ import whilst from './whilst'; * will be passed an error and any arguments passed to the final `fn`'s * callback. Invoked with (err, [results]); */ -export default function doWhilst(iteratee, test, cb) { +export default function doWhilst(fn, test, callback) { var calls = 0; - return whilst(function() { + whilst(function() { return ++calls <= 1 || test.apply(this, arguments); - }, iteratee, cb); + }, fn, callback); } diff --git a/lib/during.js b/lib/during.js index 459e144..1013bc8 100644 --- a/lib/during.js +++ b/lib/during.js @@ -38,12 +38,12 @@ import rest from 'lodash/rest'; * } * ); */ -export default function during(test, iteratee, cb) { - cb = cb || noop; +export default function during(test, fn, callback) { + callback = callback || noop; var next = rest(function(err, args) { if (err) { - cb(err); + callback(err); } else { args.push(check); test.apply(this, args); @@ -51,9 +51,9 @@ export default function during(test, iteratee, cb) { }); var check = function(err, truth) { - if (err) return cb(err); - if (!truth) return cb(null); - iteratee(next); + if (err) return callback(err); + if (!truth) return callback(null); + fn(next); }; test(check); diff --git a/lib/eachLimit.js b/lib/eachLimit.js index 0b46c0b..d5f200c 100644 --- a/lib/eachLimit.js +++ b/lib/eachLimit.js @@ -21,6 +21,6 @@ import withoutIndex from './internal/withoutIndex'; * @param {Function} [callback] - A callback which is called when all * `iteratee` functions have finished, or an error occurs. Invoked with (err). */ -export default function eachLimit(arr, limit, iteratee, cb) { - return eachOfLimit(limit)(arr, withoutIndex(iteratee), cb); +export default function eachLimit(coll, limit, iteratee, callback) { + eachOfLimit(limit)(coll, withoutIndex(iteratee), callback); } diff --git a/lib/eachOfLimit.js b/lib/eachOfLimit.js index d86dd9c..5810f8f 100644 --- a/lib/eachOfLimit.js +++ b/lib/eachOfLimit.js @@ -21,6 +21,6 @@ import _eachOfLimit from './internal/eachOfLimit'; * @param {Function} [callback] - A callback which is called when all * `iteratee` functions have finished, or an error occurs. Invoked with (err). */ -export default function eachOfLimit(obj, limit, iteratee, cb) { - _eachOfLimit(limit)(obj, iteratee, cb); +export default function eachOfLimit(coll, limit, iteratee, callback) { + _eachOfLimit(limit)(coll, iteratee, callback); } diff --git a/lib/forever.js b/lib/forever.js index 37fae48..4708d21 100644 --- a/lib/forever.js +++ b/lib/forever.js @@ -31,8 +31,8 @@ import ensureAsync from './ensureAsync'; * } * ); */ -export default function forever(fn, cb) { - var done = onlyOnce(cb || noop); +export default function forever(fn, errback) { + var done = onlyOnce(errback || noop); var task = ensureAsync(fn); function next(err) { diff --git a/lib/internal/eachOfLimit.js b/lib/internal/eachOfLimit.js index 15dba57..5e83463 100644 --- a/lib/internal/eachOfLimit.js +++ b/lib/internal/eachOfLimit.js @@ -31,6 +31,7 @@ export default function _eachOfLimit(limit) { return; } running += 1; + /* eslint {no-loop-func: 0} */ iteratee(elem.value, elem.key, onlyOnce(function (err) { running -= 1; if (err) { diff --git a/lib/internal/setImmediate.js b/lib/internal/setImmediate.js index eb4ea63..1efa1a3 100644 --- a/lib/internal/setImmediate.js +++ b/lib/internal/setImmediate.js @@ -11,10 +11,10 @@ export function fallback(fn) { export function wrap(defer) { return rest(function (fn, args) { - defer(function () { - fn.apply(null, args); - }); - }); + defer(function () { + fn.apply(null, args); + }); + }); } var _defer; diff --git a/lib/memoize.js b/lib/memoize.js index 60c1f54..5b06cff 100644 --- a/lib/memoize.js +++ b/lib/memoize.js @@ -30,6 +30,7 @@ function has(obj, key) { * @param {Function} hasher - An optional function for generating a custom hash * for storing results. It has all the arguments applied to it apart from the * callback, and must be synchronous. + * @returns {Function} a memoized version of `fn` * @example * * var slow_fn = function(name, callback) { diff --git a/lib/parallelLimit.js b/lib/parallelLimit.js index 6d400d7..2eb8b2f 100644 --- a/lib/parallelLimit.js +++ b/lib/parallelLimit.js @@ -20,6 +20,6 @@ import parallel from './internal/parallel'; * (or object) containing all the result arguments passed to the task callbacks. * Invoked with (err, results). */ -export default function parallelLimit(tasks, limit, cb) { - return parallel(eachOfLimit(limit), tasks, cb); +export default function parallelLimit(tasks, limit, callback) { + parallel(eachOfLimit(limit), tasks, callback); } diff --git a/lib/race.js b/lib/race.js index 0cead40..2b8ad39 100644 --- a/lib/race.js +++ b/lib/race.js @@ -19,6 +19,7 @@ import once from './internal/once'; * @param {Function} callback - A callback to run once any of the functions have * completed. This function gets an error or result from the first function that * completed. Invoked with (err, result). + * @returns undefined * @example * * async.race([ @@ -38,11 +39,11 @@ import once from './internal/once'; * // the result will be equal to 'two' as it finishes earlier * }); */ -export default function race(tasks, cb) { - cb = once(cb || noop); - if (!isArray(tasks)) return cb(new TypeError('First argument to race must be an array of functions')); - if (!tasks.length) return cb(); +export default function race(tasks, callback) { + callback = once(callback || noop); + if (!isArray(tasks)) return callback(new TypeError('First argument to race must be an array of functions')); + if (!tasks.length) return callback(); each(tasks, function (task) { - task(cb); + task(callback); }); } diff --git a/lib/reduce.js b/lib/reduce.js index 1d85ebe..8f529a0 100644 --- a/lib/reduce.js +++ b/lib/reduce.js @@ -14,7 +14,8 @@ import eachOfSeries from './eachOfSeries'; * @name reduce * @static * @memberOf async - * @alias inject, foldl + * @alias inject + * @alias foldl * @category Collection * @param {Array|Object} coll - A collection to iterate over. * @param {*} memo - The initial state of the reduction. @@ -38,13 +39,13 @@ import eachOfSeries from './eachOfSeries'; * // result is now equal to the last value of memo, which is 6 * }); */ -export default function reduce(arr, memo, iteratee, cb) { - eachOfSeries(arr, function(x, i, cb) { +export default function reduce(coll, memo, iteratee, callback) { + eachOfSeries(coll, function(x, i, callback) { iteratee(memo, x, function(err, v) { memo = v; - cb(err); + callback(err); }); }, function(err) { - cb(err, memo); + callback(err, memo); }); } diff --git a/lib/reduceRight.js b/lib/reduceRight.js index eb3d78f..fda0505 100644 --- a/lib/reduceRight.js +++ b/lib/reduceRight.js @@ -23,7 +23,7 @@ var slice = Array.prototype.slice; * `iteratee` functions have finished. Result is the reduced value. Invoked with * (err, result). */ -export default function reduceRight (arr, memo, iteratee, cb) { - var reversed = slice.call(arr).reverse(); - reduce(reversed, memo, iteratee, cb); +export default function reduceRight (coll, memo, iteratee, callback) { + var reversed = slice.call(coll).reverse(); + reduce(reversed, memo, iteratee, callback); } diff --git a/lib/reflect.js b/lib/reflect.js index a4c3ac6..63adefb 100644 --- a/lib/reflect.js +++ b/lib/reflect.js @@ -11,7 +11,7 @@ import rest from 'lodash/rest'; * @static * @memberOf async * @category Util - * @param {Function} function - The function you want to wrap + * @param {Function} fn - The function you want to wrap * @returns {Function} - A function that always passes null to it's callback as * the error. The second argument to the callback will be an `object` with * either an `error` or a `value` property. diff --git a/lib/retry.js b/lib/retry.js index 3aa4b6a..69c3eb3 100644 --- a/lib/retry.js +++ b/lib/retry.js @@ -71,11 +71,11 @@ import constant from 'lodash/constant'; * // do something with the results * }); */ -export default function retry(times, task, callback) { +export default function retry(opts, task, callback) { var DEFAULT_TIMES = 5; var DEFAULT_INTERVAL = 0; - var opts = { + var options = { times: DEFAULT_TIMES, intervalFunc: constant(DEFAULT_INTERVAL) }; @@ -95,11 +95,11 @@ export default function retry(times, task, callback) { } - if (arguments.length < 3 && typeof times === 'function') { + if (arguments.length < 3 && typeof opts === 'function') { callback = task || noop; - task = times; + task = opts; } else { - parseTimes(opts, times); + parseTimes(options, opts); callback = callback || noop; } @@ -109,10 +109,10 @@ export default function retry(times, task, callback) { } var attempts = []; - for (var i = 1; i < opts.times + 1; i++) { - var isFinalAttempt = (i == opts.times); + for (var i = 1; i < options.times + 1; i++) { + var isFinalAttempt = (i == options.times); attempts.push(retryAttempt(isFinalAttempt)); - var interval = opts.intervalFunc(i); + var interval = options.intervalFunc(i); if (!isFinalAttempt && interval > 0) { attempts.push(retryInterval(interval)); } @@ -15,6 +15,7 @@ import reduce from './reduce'; * @see async.compose * @category Control Flow * @param {...Function} functions - the asynchronous functions to compose + * @returns {Function} a function that composes the `functions` in order * @example * * // Requires lodash (or underscore), express3 and dresende's orm2. @@ -38,8 +39,7 @@ import reduce from './reduce'; * }); * }); */ -export default function seq( /* functions... */ ) { - var fns = arguments; +export default rest(function seq(functions) { return rest(function(args) { var that = this; @@ -50,13 +50,13 @@ export default function seq( /* functions... */ ) { cb = noop; } - reduce(fns, args, function(newargs, fn, cb) { - fn.apply(that, newargs.concat([rest(function(err, nextargs) { - cb(err, nextargs); - })])); - }, - function(err, results) { - cb.apply(that, [err].concat(results)); - }); + reduce(functions, args, function(newargs, fn, cb) { + fn.apply(that, newargs.concat([rest(function(err, nextargs) { + cb(err, nextargs); + })])); + }, + function(err, results) { + cb.apply(that, [err].concat(results)); + }); }); -} +}) diff --git a/lib/series.js b/lib/series.js index 72034e9..3345519 100644 --- a/lib/series.js +++ b/lib/series.js @@ -64,6 +64,6 @@ import eachOfSeries from './eachOfSeries'; * // results is now equal to: {one: 1, two: 2} * }); */ -export default function series(tasks, cb) { - return parallel(eachOfSeries, tasks, cb); +export default function series(tasks, callback) { + parallel(eachOfSeries, tasks, callback); } diff --git a/lib/sortBy.js b/lib/sortBy.js index 6dfad9b..539a829 100644 --- a/lib/sortBy.js +++ b/lib/sortBy.js @@ -48,15 +48,15 @@ import map from './map'; * // result callback * }); */ -export default function sortBy (arr, iteratee, cb) { - map(arr, function (x, cb) { +export default function sortBy (coll, iteratee, callback) { + map(coll, function (x, callback) { iteratee(x, function (err, criteria) { - if (err) return cb(err); - cb(null, {value: x, criteria: criteria}); + if (err) return callback(err); + callback(null, {value: x, criteria: criteria}); }); }, function (err, results) { - if (err) return cb(err); - cb(null, arrayMap(results.sort(comparator), property('value'))); + if (err) return callback(err); + callback(null, arrayMap(results.sort(comparator), property('value'))); }); function comparator(left, right) { diff --git a/lib/timeout.js b/lib/timeout.js index 1d19643..2186c1b 100644 --- a/lib/timeout.js +++ b/lib/timeout.js @@ -9,7 +9,7 @@ import initialParams from './internal/initialParams'; * @static * @memberOf async * @category Util - * @param {Function} function - The asynchronous function you want to set the + * @param {Function} asyncFn - The asynchronous function you want to set the * time limit. * @param {number} miliseconds - The specified time limit. * @param {*} [info] - Any variable you want attached (`string`, `object`, etc) diff --git a/lib/timesLimit.js b/lib/timesLimit.js index 5e8e52f..b4db62c 100644 --- a/lib/timesLimit.js +++ b/lib/timesLimit.js @@ -10,12 +10,12 @@ import range from 'lodash/_baseRange'; * @memberOf async * @see async.times * @category Control Flow - * @param {number} n - The number of times to run the function. + * @param {number} count - The number of times to run the function. * @param {number} limit - The maximum number of async operations at a time. * @param {Function} iteratee - The function to call `n` times. Invoked with the * iteration index and a callback (n, next). * @param {Function} callback - see {@link async.map}. */ -export default function timeLimit(count, limit, iteratee, cb) { - return mapLimit(range(0, count, 1), limit, iteratee, cb); +export default function timeLimit(count, limit, iteratee, callback) { + mapLimit(range(0, count, 1), limit, iteratee, callback); } diff --git a/lib/transform.js b/lib/transform.js index 1c20fce..55fd067 100644 --- a/lib/transform.js +++ b/lib/transform.js @@ -46,16 +46,16 @@ import eachOf from './eachOf'; * // result is equal to {a: 2, b: 4, c: 6} * }) */ -export default function transform (arr, acc, iteratee, callback) { +export default function transform (coll, accumulator, iteratee, callback) { if (arguments.length === 3) { callback = iteratee; - iteratee = acc; - acc = isArray(arr) ? [] : {}; + iteratee = accumulator; + accumulator = isArray(coll) ? [] : {}; } - eachOf(arr, function(v, k, cb) { - iteratee(acc, v, k, cb); + eachOf(coll, function(v, k, cb) { + iteratee(accumulator, v, k, cb); }, function(err) { - callback(err, acc); + callback(err, accumulator); }); } diff --git a/lib/unmemoize.js b/lib/unmemoize.js index 676e7c0..e7d9765 100644 --- a/lib/unmemoize.js +++ b/lib/unmemoize.js @@ -8,6 +8,7 @@ * @see async.memoize * @category Util * @param {Function} fn - the memoized function + * @returns {Function} a function that calls the original unmemoized function */ export default function unmemoize(fn) { return function () { diff --git a/lib/until.js b/lib/until.js index cce9432..910e049 100644 --- a/lib/until.js +++ b/lib/until.js @@ -22,8 +22,8 @@ import whilst from './whilst'; * will be passed an error and any arguments passed to the final `fn`'s * callback. Invoked with (err, [results]); */ -export default function until(test, iteratee, cb) { - return whilst(function() { +export default function until(test, fn, callback) { + whilst(function() { return !test.apply(this, arguments); - }, iteratee, cb); + }, fn, callback); } diff --git a/lib/waterfall.js b/lib/waterfall.js index 62bbdfe..9478bd9 100644 --- a/lib/waterfall.js +++ b/lib/waterfall.js @@ -22,6 +22,7 @@ import onlyOnce from './internal/onlyOnce'; * @param {Function} [callback] - An optional callback to run once all the * functions have completed. This will be passed the results of the last task's * callback. Invoked with (err, [results]). + * @returns undefined * @example * * async.waterfall([ @@ -60,20 +61,20 @@ import onlyOnce from './internal/onlyOnce'; * callback(null, 'done'); * } */ -export default function(tasks, cb) { - cb = once(cb || noop); - if (!isArray(tasks)) return cb(new Error('First argument to waterfall must be an array of functions')); - if (!tasks.length) return cb(); +export default function(tasks, callback) { + callback = once(callback || noop); + if (!isArray(tasks)) return callback(new Error('First argument to waterfall must be an array of functions')); + if (!tasks.length) return callback(); var taskIndex = 0; function nextTask(args) { if (taskIndex === tasks.length) { - return cb.apply(null, [null].concat(args)); + return callback.apply(null, [null].concat(args)); } var taskCallback = onlyOnce(rest(function(err, args) { if (err) { - return cb.apply(null, [err].concat(args)); + return callback.apply(null, [err].concat(args)); } nextTask(args); })); diff --git a/lib/whilst.js b/lib/whilst.js index 079fd85..ee1c19a 100644 --- a/lib/whilst.js +++ b/lib/whilst.js @@ -11,13 +11,14 @@ import rest from 'lodash/rest'; * @category Control Flow * @param {Function} test - synchronous truth test to perform before each * execution of `fn`. Invoked with (). - * @param {Function} fn - A function which is called each time `test` passes. + * @param {Function} iteratee - A function which is called each time `test` passes. * The function is passed a `callback(err)`, which must be called once it has * completed with an optional `err` argument. Invoked with (callback). * @param {Function} [callback] - A callback which is called after the test * function has failed and repeated execution of `fn` has stopped. `callback` * will be passed an error and any arguments passed to the final `fn`'s * callback. Invoked with (err, [results]); + * @returns undefined * @example * * var count = 0; @@ -34,13 +35,13 @@ import rest from 'lodash/rest'; * } * ); */ -export default function whilst(test, iteratee, cb) { - cb = cb || noop; - if (!test()) return cb(null); +export default function whilst(test, iteratee, callback) { + callback = callback || noop; + if (!test()) return callback(null); var next = rest(function(err, args) { - if (err) return cb(err); + if (err) return callback(err); if (test.apply(this, args)) return iteratee(next); - cb.apply(null, [null].concat(args)); + callback.apply(null, [null].concat(args)); }); iteratee(next); } diff --git a/mocha_test/asyncify.js b/mocha_test/asyncify.js index 507cd1a..aae878e 100644 --- a/mocha_test/asyncify.js +++ b/mocha_test/asyncify.js @@ -3,7 +3,7 @@ var assert = require('assert'); var expect = require('chai').expect; var isBrowser = require('./support/is_browser'); -describe('asyncify', function(done){ +describe('asyncify', function(){ it('asyncify', function(done) { var parse = async.asyncify(JSON.parse); @@ -26,16 +26,16 @@ describe('asyncify', function(done){ }); it('variable numbers of arguments', function(done) { - async.asyncify(function (x, y, z) { - return arguments; - })(1, 2, 3, function (err, result) { - expect(result.length).to.equal(3); - expect(result[0]).to.equal(1); - expect(result[1]).to.equal(2); - expect(result[2]).to.equal(3); - done(); - }); - }); + async.asyncify(function (/*x, y, z*/) { + return arguments; + })(1, 2, 3, function (err, result) { + expect(result.length).to.equal(3); + expect(result[0]).to.equal(1); + expect(result[1]).to.equal(2); + expect(result[2]).to.equal(3); + done(); + }); + }); it('catch errors', function(done) { async.asyncify(function () { diff --git a/mocha_test/auto.js b/mocha_test/auto.js index 6d30815..55f3b25 100644 --- a/mocha_test/auto.js +++ b/mocha_test/auto.js @@ -112,29 +112,29 @@ describe('auto', function () { var callOrder = []; async.auto({ task1: ['task2', function(results, callback){ - expect(results.task2).to.eql('task2'); - setTimeout(function(){ - callOrder.push('task1'); - callback(null, 'task1a', 'task1b'); - }, 25); - }], + expect(results.task2).to.eql('task2'); + setTimeout(function(){ + callOrder.push('task1'); + callback(null, 'task1a', 'task1b'); + }, 25); + }], task2: function(callback){ - setTimeout(function(){ - callOrder.push('task2'); - callback(null, 'task2'); - }, 50); - }, + setTimeout(function(){ + callOrder.push('task2'); + callback(null, 'task2'); + }, 50); + }, task3: ['task2', function(results, callback){ - expect(results.task2).to.eql('task2'); - callOrder.push('task3'); - callback(null); - }], + expect(results.task2).to.eql('task2'); + callOrder.push('task3'); + callback(null); + }], task4: ['task1', 'task2', function(results, callback){ - expect(results.task1).to.eql(['task1a','task1b']); - expect(results.task2).to.eql('task2'); - callOrder.push('task4'); - callback(null, 'task4'); - }] + expect(results.task1).to.eql(['task1a','task1b']); + expect(results.task2).to.eql('task2'); + callOrder.push('task4'); + callback(null, 'task4'); + }] }, function(err, results){ expect(callOrder).to.eql(['task2','task3','task1','task4']); @@ -155,7 +155,7 @@ describe('auto', function () { task1: function(callback){ callback('testerror'); }, - task2: ['task1', function(results, callback){ + task2: ['task1', function(/*results, callback*/){ throw new Error('task2 should not be called'); }], task3: function(callback){ @@ -328,7 +328,7 @@ describe('auto', function () { task1: function (callback) { callback('error'); }, - task2: function (callback) { + task2: function (/*callback*/) { throw new Error('test2 should not be called'); } }, 1, function (error) { diff --git a/mocha_test/autoInject.js b/mocha_test/autoInject.js index 39c99a4..d699453 100644 --- a/mocha_test/autoInject.js +++ b/mocha_test/autoInject.js @@ -1,6 +1,5 @@ var async = require('../lib'); var expect = require('chai').expect; -var _ = require('lodash'); describe('autoInject', function () { @@ -88,9 +87,7 @@ describe('autoInject', function () { var arrowSupport = true; try { - /* jshint -W054 */ new Function('x => x'); - /* jshint +W054 */ } catch (e) { arrowSupport = false; } @@ -98,7 +95,7 @@ describe('autoInject', function () { if (arrowSupport) { // Needs to be run on ES6 only - /* jshint -W061 */ + /* eslint {no-eval: 0}*/ eval("(function() { " + " it('should work with es6 arrow syntax', function (done) { " + " async.autoInject({ " + @@ -113,6 +110,5 @@ describe('autoInject', function () { " }); " + "}) " )(); - /* jshint +W061 */ } }); diff --git a/mocha_test/consoleFunctions.js b/mocha_test/consoleFunctions.js index 616ac1d..3c295c8 100644 --- a/mocha_test/consoleFunctions.js +++ b/mocha_test/consoleFunctions.js @@ -1,6 +1,5 @@ var async = require('../lib'); var expect = require('chai').expect; -var assert = require('assert'); describe('console functions', function() { diff --git a/mocha_test/map.js b/mocha_test/map.js index e7d4fa3..c7f5030 100644 --- a/mocha_test/map.js +++ b/mocha_test/map.js @@ -300,8 +300,8 @@ describe("map", function() { }).to.throw(/already called/); done(); } - }, function(err) { - no_such_function(); + }, function() { + throw new Error(); }); }); }); diff --git a/mocha_test/mapValues.js b/mocha_test/mapValues.js index 44eb27d..612feff 100644 --- a/mocha_test/mapValues.js +++ b/mocha_test/mapValues.js @@ -1,6 +1,5 @@ var async = require('../lib'); var expect = require('chai').expect; -var assert = require('assert'); describe('mapValues', function () { var obj = {a: 1, b: 2, c: 3}; diff --git a/mocha_test/memoize.js b/mocha_test/memoize.js index 1a6e886..39620dd 100644 --- a/mocha_test/memoize.js +++ b/mocha_test/memoize.js @@ -153,7 +153,7 @@ describe("memoize", function() { it('manually added memo value', function(done) { var fn = async.memoize(function() { - test(false, "Function should never be called"); + throw new Error("Function should never be called"); }); fn.memo.foo = ["bar"]; fn("foo", function(val) { diff --git a/mocha_test/queue.js b/mocha_test/queue.js index 8ba5770..d514ce7 100644 --- a/mocha_test/queue.js +++ b/mocha_test/queue.js @@ -402,33 +402,33 @@ describe('queue', function(){ }); it('pause in worker with concurrency', function(done) { - var call_order = []; - var q = async.queue(function (task, callback) { - if (task.isLongRunning) { - q.pause(); - setTimeout(function () { - call_order.push(task.id); - q.resume(); - callback(); - }, 50); - } - else { + var call_order = []; + var q = async.queue(function (task, callback) { + if (task.isLongRunning) { + q.pause(); + setTimeout(function () { call_order.push(task.id); - setTimeout(callback, 10); - } - }, 10); + q.resume(); + callback(); + }, 50); + } + else { + call_order.push(task.id); + setTimeout(callback, 10); + } + }, 10); - q.push({ id: 1, isLongRunning: true}); - q.push({ id: 2 }); - q.push({ id: 3 }); - q.push({ id: 4 }); - q.push({ id: 5 }); + q.push({ id: 1, isLongRunning: true}); + q.push({ id: 2 }); + q.push({ id: 3 }); + q.push({ id: 4 }); + q.push({ id: 5 }); - q.drain = function () { - expect(call_order).to.eql([1, 2, 3, 4, 5]); - done(); - }; - }); + q.drain = function () { + expect(call_order).to.eql([1, 2, 3, 4, 5]); + done(); + }; + }); it('pause with concurrency', function(done) { var call_order = [], @@ -507,7 +507,7 @@ describe('queue', function(){ }); it('kill', function(done) { - var q = async.queue(function (task, callback) { + var q = async.queue(function (/*task, callback*/) { setTimeout(function () { throw new Error("Function should never be called"); }, 20); diff --git a/perf/memory.js b/perf/memory.js index 1a022af..1edab20 100644 --- a/perf/memory.js +++ b/perf/memory.js @@ -24,9 +24,9 @@ function waterfallTest(cb) { function func3(cb) {return cb(); } async.waterfall([ - func1, - func2, - func3 + func1, + func2, + func3 ], next); }); } @@ -38,7 +38,7 @@ function reportMemory() { global.gc(); var increase = process.memoryUsage().heapUsed - startMem; console.log("memory increase: " + - (+(increase / 1024).toPrecision(3)) + "kB"); + (+(increase / 1024).toPrecision(3)) + "kB"); } waterfallTest(function () { diff --git a/perf/suites.js b/perf/suites.js index dd8392c..244b32b 100644 --- a/perf/suites.js +++ b/perf/suites.js @@ -1,297 +1,336 @@ var _ = require("lodash"); var tasks; -module.exports = [ - { - name: "each", - // args lists are passed to the setup function - args: [[10], [300], [10000]], - setup: function(count) { - tasks = _.range(count); - }, - fn: function (async, done) { - async.each(tasks, function (num, cb) { - async.setImmediate(cb); - }, done); - } - }, - { - name: "eachSeries", - args: [[10], [300], [10000]], - setup: function(count) { - tasks = _.range(count); - }, - fn: function (async, done) { - async.eachSeries(tasks, function (num, cb) { - async.setImmediate(cb); - }, done); - } - }, - { - name: "eachLimit", - args: [[10], [300], [10000]], - setup: function(count) { - tasks = _.range(count); - }, - fn: function (async, done) { - async.eachLimit(tasks, 4, function (num, cb) { - async.setImmediate(cb); - }, done); - } - }, - { - name: "map", - // args lists are passed to the setup function - args: [[10], [300], [10000]], - setup: function(count) { - tasks = _.range(count); - }, - fn: function (async, done) { - async.map(tasks, function (num, cb) { - async.setImmediate(cb); - }, done); - } - }, - { - name: "mapSeries", - args: [[10], [300], [10000]], - setup: function(count) { - tasks = _.range(count); - }, - fn: function (async, done) { - async.mapSeries(tasks, function (num, cb) { - async.setImmediate(cb); - }, done); - } - }, - { - name: "mapLimit", - args: [[10], [300], [10000]], - setup: function(count) { - tasks = _.range(count); - }, - fn: function (async, done) { - async.mapLimit(tasks, 4, function (num, cb) { - async.setImmediate(cb); - }, done); - } - }, - { - name: "eachOf", - // args lists are passed to the setup function - args: [[10], [300], [10000]], - setup: function(count) { - tasks = _.range(count); - }, - fn: function (async, done) { - async.eachOf(tasks, function (num, i, cb) { - async.setImmediate(cb); - }, done); - } - }, - { - name: "eachOfSeries", - args: [[10], [300], [10000]], - setup: function(count) { - tasks = _.range(count); - }, - fn: function (async, done) { - async.eachOfSeries(tasks, function (num, i, cb) { - async.setImmediate(cb); - }, done); - } - }, - { - name: "eachOfLimit", - args: [[10], [300], [10000]], - setup: function(count) { - tasks = _.range(count); - }, - fn: function (async, done) { - async.eachOfLimit(tasks, 4, function (num, i, cb) { - async.setImmediate(cb); - }, done); - } - }, - { - name: "parallel", - args: [[10], [100], [1000]], - setup: function (count) { - tasks = _.range(count).map(function () { - return function (cb) { - setImmediate(cb); - }; - }); - }, - fn: function (async, done) { - async.parallel(tasks, done); - } - }, - { - name: "series", - args: [[10], [100], [1000]], - setup: function (count) { - tasks = _.range(count).map(function () { - return function (cb) { setImmediate(cb); }; - }); - }, - fn: function (async, done) { - async.series(tasks, done); - } - }, - { - name: "waterfall", - args: [[10], [100], [1000]], - setup: function (count) { - tasks = [ - function (cb) { - return cb(null, 1); - } - ].concat(_.range(count).map(function (i) { - return function (arg, cb) { - setImmediate(function () { +module.exports = [{ + name: "each", + // args lists are passed to the setup function + args: [ + [10], + [300], + [10000] + ], + setup: function(count) { + tasks = _.range(count); + }, + fn: function(async, done) { + async.each(tasks, function(num, cb) { + async.setImmediate(cb); + }, done); + } +}, { + name: "eachSeries", + args: [ + [10], + [300], + [10000] + ], + setup: function(count) { + tasks = _.range(count); + }, + fn: function(async, done) { + async.eachSeries(tasks, function(num, cb) { + async.setImmediate(cb); + }, done); + } +}, { + name: "eachLimit", + args: [ + [10], + [300], + [10000] + ], + setup: function(count) { + tasks = _.range(count); + }, + fn: function(async, done) { + async.eachLimit(tasks, 4, function(num, cb) { + async.setImmediate(cb); + }, done); + } +}, { + name: "map", + // args lists are passed to the setup function + args: [ + [10], + [300], + [10000] + ], + setup: function(count) { + tasks = _.range(count); + }, + fn: function(async, done) { + async.map(tasks, function(num, cb) { + async.setImmediate(cb); + }, done); + } +}, { + name: "mapSeries", + args: [ + [10], + [300], + [10000] + ], + setup: function(count) { + tasks = _.range(count); + }, + fn: function(async, done) { + async.mapSeries(tasks, function(num, cb) { + async.setImmediate(cb); + }, done); + } +}, { + name: "mapLimit", + args: [ + [10], + [300], + [10000] + ], + setup: function(count) { + tasks = _.range(count); + }, + fn: function(async, done) { + async.mapLimit(tasks, 4, function(num, cb) { + async.setImmediate(cb); + }, done); + } +}, { + name: "eachOf", + // args lists are passed to the setup function + args: [ + [10], + [300], + [10000] + ], + setup: function(count) { + tasks = _.range(count); + }, + fn: function(async, done) { + async.eachOf(tasks, function(num, i, cb) { + async.setImmediate(cb); + }, done); + } +}, { + name: "eachOfSeries", + args: [ + [10], + [300], + [10000] + ], + setup: function(count) { + tasks = _.range(count); + }, + fn: function(async, done) { + async.eachOfSeries(tasks, function(num, i, cb) { + async.setImmediate(cb); + }, done); + } +}, { + name: "eachOfLimit", + args: [ + [10], + [300], + [10000] + ], + setup: function(count) { + tasks = _.range(count); + }, + fn: function(async, done) { + async.eachOfLimit(tasks, 4, function(num, i, cb) { + async.setImmediate(cb); + }, done); + } +}, { + name: "parallel", + args: [ + [10], + [100], + [1000] + ], + setup: function(count) { + tasks = _.range(count).map(function() { + return function(cb) { + setImmediate(cb); + }; + }); + }, + fn: function(async, done) { + async.parallel(tasks, done); + } +}, { + name: "series", + args: [ + [10], + [100], + [1000] + ], + setup: function(count) { + tasks = _.range(count).map(function() { + return function(cb) { + setImmediate(cb); + }; + }); + }, + fn: function(async, done) { + async.series(tasks, done); + } +}, { + name: "waterfall", + args: [ + [10], + [100], + [1000] + ], + setup: function(count) { + tasks = [ + function(cb) { + return cb(null, 1); + } + ].concat(_.range(count).map(function(i) { + return function(arg, cb) { + setImmediate(function() { cb(null, i); }); }; })); - }, - fn: function (async, done) { - async.waterfall(tasks, done); - } - }, - { - name: "queue", - args: [[1000], [30000], [100000], [200000]], - setup: function (count) { - tasks = count; - }, - fn: function (async, done) { - var numEntries = tasks; - var q = async.queue(worker, 1); - for (var i = 1; i <= numEntries; i++) { - q.push({num: i}); - } - function worker(task, callback) { - if (task.num === numEntries) { - return done(); - } - setImmediate(callback); - } - } - }, - { - name: "some - no short circuit- false", - // args lists are passed to the setup function - args: [[500]], - setup: function(count) { - tasks = _.range(count); - }, - fn: function (async, done) { - async.some(tasks, function(i, cb) { - async.setImmediate(function() { - cb(i >= 600); - }); - }, done); - } - }, - { - name: "some - short circuit - true", - // args lists are passed to the setup function - args: [[500]], - setup: function(count) { - tasks = _.range(count); - }, - fn: function (async, done) { - async.some(tasks, function(i, cb) { - async.setImmediate(function() { - cb(i >= 60); - }); - }, done); - } - }, - { - name: "every - no short circuit- true", - // args lists are passed to the setup function - args: [[500]], - setup: function(count) { - tasks = _.range(count); - }, - fn: function (async, done) { - async.every(tasks, function(i, cb) { - async.setImmediate(function() { - cb(i <= 600); - }); - }, done); - } - }, - { - name: "every - short circuit - false", - // args lists are passed to the setup function - args: [[500]], - setup: function(count) { - tasks = _.range(count); - }, - fn: function (async, done) { - async.every(tasks, function(i, cb) { - async.setImmediate(function() { - cb(i <= 60); - }); - }, done); - } - }, - { - name: "defer nextTick", - fn: function (async, done) { - process.nextTick(done); - } - }, - { - name: "defer setImmediate", - fn: function (async, done) { - setImmediate(done); - } - }, - { - name: "defer async.nextTick", - fn: function (async, done) { - async.nextTick(done); - } - }, - { - name: "defer async.setImmediate", - fn: function (async, done) { - async.setImmediate(done); - } - }, - { - name: "defer setTimeout", - fn: function (async, done) { - setTimeout(done, 0); - } - }, - { - name: "ensureAsync sync", - fn: function (async, done) { - async.ensureAsync(function (cb) { - cb(); - })(done); - } - }, - { - name: "ensureAsync async", - fn: function (async, done) { - async.ensureAsync(function (cb) { - setImmediate(cb); - })(done); - } - }, - { - name: "ensureAsync async noWrap", - fn: function (async, done) { - (function (cb) { - setImmediate(cb); - }(done)); - } - } -]; + }, + fn: function(async, done) { + async.waterfall(tasks, done); + } +}, { + name: "queue", + args: [ + [1000], + [30000], + [100000], + [200000] + ], + setup: function(count) { + tasks = count; + }, + fn: function(async, done) { + var numEntries = tasks; + var q = async.queue(worker, 1); + for (var i = 1; i <= numEntries; i++) { + q.push({ + num: i + }); + } + function worker(task, callback) { + if (task.num === numEntries) { + return done(); + } + setImmediate(callback); + } + } +}, { + name: "some - no short circuit- false", + // args lists are passed to the setup function + args: [ + [500] + ], + setup: function(count) { + tasks = _.range(count); + }, + fn: function(async, done) { + async.some(tasks, function(i, cb) { + async.setImmediate(function() { + cb(i >= 600); + }); + }, done); + } +}, { + name: "some - short circuit - true", + // args lists are passed to the setup function + args: [ + [500] + ], + setup: function(count) { + tasks = _.range(count); + }, + fn: function(async, done) { + async.some(tasks, function(i, cb) { + async.setImmediate(function() { + cb(i >= 60); + }); + }, done); + } +}, { + name: "every - no short circuit- true", + // args lists are passed to the setup function + args: [ + [500] + ], + setup: function(count) { + tasks = _.range(count); + }, + fn: function(async, done) { + async.every(tasks, function(i, cb) { + async.setImmediate(function() { + cb(i <= 600); + }); + }, done); + } +}, { + name: "every - short circuit - false", + // args lists are passed to the setup function + args: [ + [500] + ], + setup: function(count) { + tasks = _.range(count); + }, + fn: function(async, done) { + async.every(tasks, function(i, cb) { + async.setImmediate(function() { + cb(i <= 60); + }); + }, done); + } +}, { + name: "defer nextTick", + fn: function(async, done) { + process.nextTick(done); + } +}, { + name: "defer setImmediate", + fn: function(async, done) { + setImmediate(done); + } +}, { + name: "defer async.nextTick", + fn: function(async, done) { + async.nextTick(done); + } +}, { + name: "defer async.setImmediate", + fn: function(async, done) { + async.setImmediate(done); + } +}, { + name: "defer setTimeout", + fn: function(async, done) { + setTimeout(done, 0); + } +}, { + name: "ensureAsync sync", + fn: function(async, done) { + async.ensureAsync(function(cb) { + cb(); + })(done); + } +}, { + name: "ensureAsync async", + fn: function(async, done) { + async.ensureAsync(function(cb) { + setImmediate(cb); + })(done); + } +}, { + name: "ensureAsync async noWrap", + fn: function(async, done) { + (function(cb) { + setImmediate(cb); + }(done)); + } +}]; |