update-batcher
v1.0.0
Published
Batches all the calls to an update function to reduce calls to the database
Downloads
2
Readme
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)