npm.io
0.0.5 • Published 4 years ago

lazy-batch

Licence
MIT
Version
0.0.5
Deps
1
Size
7 kB
Vulns
0
Weekly
0

lazy-batch

Run tasks lazily in batches

  • Process when the num of inputs reaches limit
  • Process after max delay

Installation

$ npm install lazy-batch
# or
$ yarn add lazy-batch

Usage

import { LazyBatch } from "lazy-batch";

const batchProcess = (inputs: number[]) => {
  console.log(inputs);
}
const lazyBatch = new LazyBatch<number>(batchProcess, { maxLength: 2, maxDelay: 3000 });
lazyBatch.add(123);
lazyBatch.add(456);

// See [ 123, 456 ]