How to use the reduce function from async

Find comprehensive JavaScript async.reduce code examples handpicked from public code repositorys.

3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
* @param {Function} [callback] - A callback which is called after all the
* `iteratee` functions have finished. Result is the reduced value. Invoked with
* (err, result).
* @example
*
* async.reduce([1,2,3], 0, function(memo, item, callback) {
*     // pointless async:
*     process.nextTick(function() {
*         callback(null, memo + item)
*     });
fork icon0
star icon2
watch icon1

89
90
91
92
93
94
95
96
97
98
const modelInfo = {
	projectID: project.id,
	projectName: project.friendlyName,
};

const packages = await async.reduce(data.collectionData.dataBaseNames, [], async (result, datasetName) => {
	log.info(`Process dataset "${datasetName}"`);
	log.progress(`Process dataset "${datasetName}"`, datasetName);

	const dataset = await bigQueryHelper.getDataset(datasetName);
fork icon7
star icon0
watch icon4

1229
1230
1231
1232
1233
1234
1235
1236
1237
1238

// reduce only has a series version, as doing reduce in parallel won't
// work in many situations.
async.inject
	= async.foldl
	= async.reduce
		= function (arr, memo, iterator, callback) {
				async.eachOfSeries(
					arr,
					function (x, i, callback) {
fork icon0
star icon0
watch icon2

+ 14 other calls in file

485
486
487
488
489
490
491
492
493
494
495
  //
  if (!callback) {
    return common.merge(names.reduce(saveStoreSync, []));
  }


  async.reduce(names, [], saveStore, function (err, objs) {
    return err ? callback(err) : callback(null, common.merge(objs));
  });
};

fork icon0
star icon0
watch icon2

1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
    args.pop();
} else {
    callback = noop;
}

async.reduce(fns, args, function (newargs, fn, cb) {
    fn.apply(that, newargs.concat([_restParam(function (err, nextargs) {
        cb(err, nextargs);
    })]));
},
fork icon0
star icon0
watch icon0

+ 43 other calls in file

383
384
385
386
387
388
389
390
391
392
};

async.foldr =
async.reduceRight = function (arr, memo, iterator, callback) {
    var reversed = _map(arr, identity).reverse();
    async.reduce(reversed, memo, iterator, callback);
};

async.transform = function (arr, memo, iterator, callback) {
    if (arguments.length === 3) {
fork icon0
star icon0
watch icon0

+ 41 other calls in file

30
31
32
33
34
35
36
37
38
39
// Look for any many-to-one collections that are being set.
// For example, User.create({pets: [1, 2, 3]}) where `pets` is a collection of `Pet`
// via an `owner` attribute that is `model: 'user'`.
// We need to know about these so that, if any of the new children already had parents,
// those parents get `removedFrom` notifications.
async.reduce(_.keys(Model.attributes), [], function (memo, attrName, nextAttrName) {

    var attrDef = Model.attributes[attrName];
    if (
        // Does this attribute represent a plural association.
fork icon0
star icon0
watch icon1