npm.io
1.0.0 • Published 5 years ago

asynchronous-iterator

Licence
MIT
Version
1.0.0
Deps
0
Size
6 kB
Vulns
0
Weekly
0

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!!');
});

Keywords