asynchronous-iterator
v1.0.0
Published
Async Loop for Node.js
Downloads
1
Readme
Asynchronous Iterator
Asynchronous Iterator is used to iterate over a given array or range without blocking the event loop. It is helpful if you want to iterate over a large data set or range.
Documentation
Installation
$ npm install asynchronous-iterator
Usage
Iterate over an Array
const AsyncIterator = require('asynchronous-iterator');
const array = new AsyncIterator([1, 2, 3, 4]);
array.each((value, index, array) => {
console.log(value, index, array);
}).then(() => {
console.log('Finished!');
}).catch(() => {
console.log('Something went wrong!!');
});
Iterate over a Range
Example 1:
const AsyncIterator = require('asynchronous-iterator');
const range = new AsyncIterator(6);
range.each(index => {
console.log(index); // 0 - 5;
}).then(() => {
console.log('Finished!');
}).catch(() => {
console.log('Something went wrong!!');
});
Example 2:
const AsyncIterator = require('asynchronous-iterator');
const range = new AsyncIterator(3, 6);
range.each(index => {
console.log(index); // 3 - 5;
}).then(() => {
console.log('Finished!');
}).catch(() => {
console.log('Something went wrong!!');
});