1.1.0 • Published 1 year ago

async-paginator v1.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

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 }
*/
1.1.0

1 year ago

1.0.1

2 years ago

1.0.0

2 years ago