summaryrefslogtreecommitdiff
path: root/lib/groupByLimit.js
diff options
context:
space:
mode:
authorAlex Early <alexander.early@gmail.com>2018-09-30 17:00:10 -0700
committerGitHub <noreply@github.com>2018-09-30 17:00:10 -0700
commit8aecf108b3922bc5211036706a0f6f75e02bd42b (patch)
tree0f7b6bee315231ef4aefdfbee154822921de231f /lib/groupByLimit.js
parentdf41256f49c9bb3126e035c95aca7860329b6acf (diff)
downloadasync-8aecf108b3922bc5211036706a0f6f75e02bd42b.tar.gz
feat: await-able Async methods (#1572)
* make each and family awaitable * dont pretend they're AsyncFunctions * check errors * ensure function name is preserved somehow * awaitable concat * awaitable detect * awaitable every/filter * awaitable groupBy * awaitable map/mapValues * awaitable reduce * awaitable reject * awaitable some * awaitable transform * awaitable times * awaitable auto * awaitable compose/seq * awaitable whilst/until (lol) * awaitable forever * awaitable parallel/race * awaitable retry * awaitable series (lol) * awaitable tryEach * awaitable waterfall (lol) * lint * cleanup, remove noop and unused internal functions
Diffstat (limited to 'lib/groupByLimit.js')
-rw-r--r--lib/groupByLimit.js11
1 files changed, 7 insertions, 4 deletions
diff --git a/lib/groupByLimit.js b/lib/groupByLimit.js
index f0402aa..24d5c40 100644
--- a/lib/groupByLimit.js
+++ b/lib/groupByLimit.js
@@ -1,6 +1,7 @@
-import noop from './internal/noop';
import mapLimit from './mapLimit';
import wrapAsync from './internal/wrapAsync';
+import awaitify from './internal/awaitify'
+
/**
* The same as [`groupBy`]{@link module:Collections.groupBy} but runs a maximum of `limit` async operations at a time.
*
@@ -19,11 +20,11 @@ import wrapAsync from './internal/wrapAsync';
* @param {Function} [callback] - A callback which is called when all `iteratee`
* functions have finished, or an error occurs. Result is an `Object` whoses
* properties are arrays of values which returned the corresponding key.
+ * @returns {Promise} a promise, if no callback is passed
*/
-export default function(coll, limit, iteratee, callback) {
- callback = callback || noop;
+function groupByLimit(coll, limit, iteratee, callback) {
var _iteratee = wrapAsync(iteratee);
- mapLimit(coll, limit, (val, iterCb) => {
+ return mapLimit(coll, limit, (val, iterCb) => {
_iteratee(val, (err, key) => {
if (err) return iterCb(err);
return iterCb(null, {key, val});
@@ -49,3 +50,5 @@ export default function(coll, limit, iteratee, callback) {
return callback(err, result);
});
}
+
+export default awaitify(groupByLimit, 4);