callback-chunk
A simple JS library to chunk an array of callbacks asynchronously
Installation
npm:
npm install callback-chunk --save
Yarn:
yarn add callback-chunk
Usage
Import the module:
const chunk = require('callback-chunk');
Call the function with your Array of callbacks:
const ticks = 50;
const callbacks = [
() => { },
];
await chunk(
callbacks,
ticks,
console.log
);
Example
const chunk = require('callback-chunk');
async function main() {
const callbacks = new Array(30)
.fill(
() => new Promise(
resolve => setTimeout(() => resolve(), Math.floor(Math.random() * 5000))
)
);
console.log('Started chunking...');
await chunk(callbacks, 10, console.log);
console.log('Finished chunking');
}
main().catch(console.error);