Install
npm install array-chunk-reader
About
Module for reading an array by chunks using a promise
Example
const arrayChunkReader = require("array-chunk-reader");
const array = [];
for (let i = 0; i < 1000000; i++) {
array.push("item-" + i);
}
const fn = value => Promise.resolve(value);
const fnChunk = allChunkValuesList => Promise.resolve(allChunkValuesList);
const options = {
size: 100,
timeout: 10,
log: true,
from: 0,
to: array.length
}
const arrayReader = new arrayChunkReader(array, options);
arrayReader.start(fn, fnChunk).then(() => 'the end');
Api
.getCurrentChunkSize()
returns the current chunk size
.stop()
cancel all next chunks after the current