Like forEachAsync, or Promise.all(), but handling a bounded number of items at any given time.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
AJ ONeal 178672ad0d v1.0.3: use index as well il y a 4 ans
.gitignore Initial commit il y a 5 ans
LICENSE Initial commit il y a 5 ans
README.md syntax fix il y a 5 ans
batchasync.js v1.0.3: use index as well il y a 4 ans
package-lock.json v1.0.3: use index as well il y a 4 ans
package.json v1.0.3: use index as well il y a 4 ans
test.js v1.0.3: use index as well il y a 4 ans

README.md

batchasync.js

Like calling map() and resolving with Promise.all(), but handling a bounded number of items at any given time.

Want to read about it?

Install

npm install --save batchasync

Usage

// Browsers
var batchAsync = window.batchAsync;
// Node
var batchAsync = require('batchasync').batchAsync;
var batchSize = 4;
var things = ['apples', 'bananas', 'pears'];

function doStuff() {
	// ... go fetch things
}

batchAsync(batchSize, things, doStuff).then(function(results) {
	// all results, in order, just like Promise.all()
	console.log(results[0]);
});

A note on undefined

Returning undefined will cause an exception to be thrown, and the Promise to be rejected.

This is on purpose - because undefined is indistinguishable from a skipped Promise.

Return null instead.

Example (bad):

function doStuff(thing) {
	// Oops! forgot to return
	request('https://searchallthe.pictures/api/' + thing);
}

Example (good):

function doStuff(thing) {
	return request('https://searchallthe.pictures/api/' + thing);
}

Example (good):

function doStuff(thing) {
	return null;
}