@tix-factory/batch
TypeScript icon, indicating that this package has built-in type declarations

1.1.0 • Public • Published

🛒 @tix-factory/batch

This module was created with the intention of merging multiple outbound fetch calls into a single outbound fetch call.

🧫 Example

import { Batch, BatchItem } from '@tix-factory/batch';

class ItemBatcher<number, string> extends Batch {
  constructor() {
    super({});
  }

  process(items: BatchItem<number, string>[]): Promise<void> {
    // All enqueued items getting processed at once.
    items.forEach((item) => {
      item.resolve(`Hello, ${item.value}`);
    });

    // Items must have either called resolve or reject before this method returns.
    return Promise.resolve();
  }
}

const batcher = new ItemBatcher();

const a = batcher.enqueue(123);
const b = batcher.enqueue(456);

Promise.all([a, b])
  .then((results) => {
    console.log(results);
  })
  .catch((err) => {
    console.error(err);
  });

Readme

Keywords

none

Package Sidebar

Install

npm i @tix-factory/batch

Weekly Downloads

1

Version

1.1.0

License

none

Unpacked Size

35.5 kB

Total Files

35

Last publish

Collaborators

  • webgl3d