README
batch-do
Do batched tasks easily
Features
- Relatively fast
- Single micro-task batching
- ESM & CJS compatible
How it works
Installation
We recommend install via npm
because of it's cache and flat node modules tree
npm i batch-do
then you able to import to Node.js/Browser easily
// Node.js
const batch = require("batch-do");
const { createContext } = batch;
// ES6
import batch, { createContext } from "batch-do";
Usage
const [state: number, setState: (value: number) => void] = React.useState(0);
batch(() => {
setState(state + 1);
});
Documentation
batch
batch(() => {
console.log("log 1");
}, ctx?);
batch(() => {
console.log("log 2");
}, ctx?);
// log 1
// log 2
Arguments list
ctx
- Context list
createContext
const ctx = createContext(
resolveBatchs,
pendingResolve,
awaitBatch,
maxCallsPerBatch
);
Arguments list
resolveBatchs
- Function to apply batched functions and frees up current batch pending listpendingResolve
- Function to resolve apply batchs functionawaitBatch
- Merge all async batches into single call or orderedmaxCallsPerBatch
- Argument to enable max limit for batches
License
MIT