async-paginator
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

paginator

Smart pagination for big collections

Ordered paginator

import { paginator } from 'async-paginator';
const paginate = paginator([1,2,3,4], async (num) => num * 10);
for await (const result of paginate) {
    console.log('Task:', result);
}
// Output will be
/*
Task: 10
Task: 20
Task: 30
Task: 40
*/

Unordered paginator

import { paginatorUnordered } from 'async-paginator';
const paginate = paginatorUnordered([1,2,3,4], async () => {
    if (num % 2 === 0) {
        await sleep(10); // timeout 10ms
    }
    return num * 10;
});
for await (const result of paginate) {
    console.log('Task:', result);
}
// Output will be
/*
Task: { data: 10, index: 0 }
Task: { data: 30, index: 2 }
Task: { data: 20, index: 1 }
Task: { data: 40, index: 3 }
*/

Readme

Keywords

none

Package Sidebar

Install

npm i async-paginator

Weekly Downloads

2

Version

1.1.0

License

MIT

Unpacked Size

231 kB

Total Files

43

Last publish

Collaborators

  • lexich