0.0.6 • Published 4 years ago

batch-do v0.0.6

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

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 list
  • pendingResolve - Function to resolve apply batchs function
  • awaitBatch - Merge all async batches into single call or ordered
  • maxCallsPerBatch - Argument to enable max limit for batches

License

MIT

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago