Skip to content
/ piter Public

piter allows abstract pagination with the convenience of async iterators

Notifications You must be signed in to change notification settings

brigand/piter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

piter allows abstract pagination with the convenience of async iterators.

import { CursorBase } from 'piter';

class Example extends CursorBase {
  pageSize = 10;
  offset = 0;

  async nextPage() {
    const array = await getData({ pageSize: this.pageSize, offset: this.offset });
    this.offset += array.length;
    return array;
  }
}

// Iterate over potentially hundreds of results in a flattened async iterator.
for await (const record of new Example()) {
  console.log(record);

  // This will slow down fetching of additional data
  await delay(100);
}

// This will allow you to process 5 items at any time
const CONCURRENCY = 5;
new Example().mapAsync(async (record, index) => {
  console.log(record);

  // This will slow down fetching of additional data, but
  // 5 of these delays can run concurrently
  await delay(500);
}, CONCURRENCY);

About

piter allows abstract pagination with the convenience of async iterators

Resources

Stars

Watchers

Forks

Packages

No packages published