update-batcher

1.0.0 • Public • Published

Update Batcher

Update Batcher batches all the calls to an update function to reduce calls to the database.

How to use

Install the library

npm install --save update-batcher

or

yarn add update-batcher

Import the module

const UpdateBatcher = require("./index");

Create an instance passing an update function and optionally a batching function

const database = { a: 1 };
 
const updater = new UpdateBatcher(x => {
  database.a = x;
});
 
// or with a custom batching function
const multiplicativeUpdater = new UpdateBatcher(x => {
  database.a = x;
}, (a, b) => a * b);

Run updates

// the update function will be called only once
updater.update(1)
updater.update(3)
updater.update(2)

/update-batcher/

    Package Sidebar

    Install

    npm i update-batcher

    Weekly Downloads

    5

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    4.58 kB

    Total Files

    4

    Last publish

    Collaborators

    • andreazanin