diff options
author | Graeme Yeates <yeatesgraeme@gmail.com> | 2016-07-09 20:13:49 -0400 |
---|---|---|
committer | Graeme Yeates <yeatesgraeme@gmail.com> | 2016-07-09 20:15:35 -0400 |
commit | b77396c5e96ce6e2a88b4bd2fa685e956a1c86ba (patch) | |
tree | d521b0b84eff65708b801a706368e025142a2bd2 /lib | |
parent | f4acefdbbe7ea4e7271a4c97da4f3e28b3404987 (diff) | |
download | async-b77396c5e96ce6e2a88b4bd2fa685e956a1c86ba.tar.gz |
Fix optional callbacks being actually optional (fixes #1223)
Diffstat (limited to 'lib')
-rw-r--r-- | lib/internal/filter.js | 3 | ||||
-rw-r--r-- | lib/mapValuesLimit.js | 4 | ||||
-rw-r--r-- | lib/reduce.js | 3 | ||||
-rw-r--r-- | lib/sortBy.js | 2 | ||||
-rw-r--r-- | lib/transform.js | 3 |
5 files changed, 14 insertions, 1 deletions
diff --git a/lib/internal/filter.js b/lib/internal/filter.js index aa5580c..35527e2 100644 --- a/lib/internal/filter.js +++ b/lib/internal/filter.js @@ -1,7 +1,10 @@ import arrayMap from 'lodash/_arrayMap'; import property from 'lodash/_baseProperty'; +import noop from 'lodash/noop'; +import once from './once'; export default function _filter(eachfn, arr, iteratee, callback) { + callback = once(callback || noop); var results = []; eachfn(arr, function (x, index, callback) { iteratee(x, function (err, v) { diff --git a/lib/mapValuesLimit.js b/lib/mapValuesLimit.js index bced034..f6e72ff 100644 --- a/lib/mapValuesLimit.js +++ b/lib/mapValuesLimit.js @@ -1,5 +1,8 @@ import eachOfLimit from './eachOfLimit'; +import noop from 'lodash/noop'; +import once from './internal/once'; + /** * The same as [`mapValues`]{@link module:Collections.mapValues} but runs a maximum of `limit` async operations at a * time. @@ -21,6 +24,7 @@ import eachOfLimit from './eachOfLimit'; * transformed values from the `obj`. Invoked with (err, result). */ export default function mapValuesLimit(obj, limit, iteratee, callback) { + callback = once(callback || noop); var newObj = {}; eachOfLimit(obj, limit, function(val, key, next) { iteratee(val, key, function (err, result) { diff --git a/lib/reduce.js b/lib/reduce.js index 8145db7..4718631 100644 --- a/lib/reduce.js +++ b/lib/reduce.js @@ -1,4 +1,6 @@ import eachOfSeries from './eachOfSeries'; +import noop from 'lodash/noop'; +import once from './internal/once'; /** * Reduces `coll` into a single value using an async `iteratee` to return each @@ -41,6 +43,7 @@ import eachOfSeries from './eachOfSeries'; * }); */ export default function reduce(coll, memo, iteratee, callback) { + callback = once(callback || noop); eachOfSeries(coll, function(x, i, callback) { iteratee(memo, x, function(err, v) { memo = v; diff --git a/lib/sortBy.js b/lib/sortBy.js index ab6c420..9b8ffe6 100644 --- a/lib/sortBy.js +++ b/lib/sortBy.js @@ -17,7 +17,7 @@ import map from './map'; * The iteratee is passed a `callback(err, sortValue)` which must be called once * it has completed with an error (which can be `null`) and a value to use as * the sort criteria. Invoked with (item, callback). - * @param {Function} [callback] - A callback which is called after all the + * @param {Function} callback - A callback which is called after all the * `iteratee` functions have finished, or an error occurs. Results is the items * from the original `coll` sorted by the values returned by the `iteratee` * calls. Invoked with (err, results). diff --git a/lib/transform.js b/lib/transform.js index 6098522..175ad85 100644 --- a/lib/transform.js +++ b/lib/transform.js @@ -1,6 +1,8 @@ import isArray from 'lodash/isArray'; +import noop from 'lodash/noop'; import eachOf from './eachOf'; +import once from './internal/once'; /** * A relative of `reduce`. Takes an Object or Array, and iterates over each @@ -53,6 +55,7 @@ export default function transform (coll, accumulator, iteratee, callback) { iteratee = accumulator; accumulator = isArray(coll) ? [] : {}; } + callback = once(callback || noop); eachOf(coll, function(v, k, cb) { iteratee(accumulator, v, k, cb); |