async-easy-group v1.0.2
async-easy-group
Group asynchronous requests together in loops and elsewhere and resolve the group after all the members have resolved
Get Started
Install with npm for use with node/webpack, or serve ./build/async-easy-group.js
to the client for use on the front end
npm i -S async-easy-group
Simple to use
Add your callback to the group, then call the done method (wait.done
in this case) when your asynchronous operations resolve
const wait = asyncGroup(10)
.then(() => {
console.log('Asynchronous calls finished');
});
Extra options
Add in a timeout length (3000
here) and call the start method prior to initializing your asynchronous calls in order to call the catch callback if your asynchronous operations fail to resolve in time
Also add in an index when you call the done method in order to seamlessly switch to using the results of each call in an array, rather than using the results provided by the final operation to resolve
const asyncGroup = require('async-easy-group');
const wait = asyncGroup(10, 3000)
.then((data) => {
console.log('Data retrieved:', data);
})
.catch((partialData) => {
console.error('Partial data retrieved:', partialData);
});
const func = index => (() => {
wait.done('some data', index);
});
wait.start();
for (let i = 0; i < 10; i++) {
setTimeout(func(i), 1000);
}