npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@blackrock-oss/micro-batcher

v1.0.0

Published

Interval-based micro batching library for TypeScript/JavaScript

Readme

Micro Batcher

Micro Batcher is a lightweight, zero-dependency, and experimental interval-based micro-batching library for TypeScript/JavaScript.

Table of Contents

Installation

npm install @blackrock-oss/micro-batcher
yarn add @blackrock-oss/micro-batcher
pnpm add @blackrock-oss/micro-batcher

Examples

The Examples Directory is a great resource for learning how to setup Micro Batcher.

Web Application is a playground application which provides example on how to configure and integrate Micro Batcher with Recoil's Data Fetching Pattern using Selector Family.

Usage

Micro Batcher in a nutshell

Micro Batcher is a decorator utility that enhances the input function with additional functionalities such as batching, throttling, and more.

By decorating the original function with Micro Batcher, it produces an enhanced function with the same function signature, allowing developers to seamlessly replace the original function with the enhanced version.

If a batching function is provided to Micro Batcher, calls to the decorated function within a short interval are intercepted, their payloads are accumulated, then forwarded to the batching or original function for processing, and the results are distributed back to the respective callers.

micro batcher demo

API Examples

Below code snippets are taken from the Example Web Application. Micro Batcher is used to generate a decorated function that is being used by data fetching workflow.

export const fetchSingleSecurity = async (cusip: string): Promise<Security> => {
  // Data Fetching Implementation
};

const batchFetchSecurities = async (cusips: string[]): Promise<Security[]> => {
  // Data Fetching Implementation
};

export const decoratedFetchSecurity = MicroBatcher(fetchSingleSecurity)
  .batchResolver(batchFetchSecurities, {
    payloadWindowSizeLimit: 4,
    batchingIntervalInMs: 50
  })
  .build();

In this example, the decorated function is being used in conjunction with Recoil's Data Fetching Pattern which combines the benefit of selector caching and automatic burst APIs batching.

export const cusipToSecuritySelectorFamily = selectorFamily<Security, string>({
  key: 'cusipToSecuritySelectorFamily',
  get:
    (cusip: string) =>
    ({ get }) => {
      const enableMicroBatcher = get(enableMicroBatcherAtom);
      if (enableMicroBatcher) {
        return decoratedFetchSecurity(cusip);
      }
      return fetchSingleSecurity(cusip);
    }
});

Other Examples

Example 1: Single Parameter Function
// Original function
const multiplyByTwo = (input: number): Promise<number> => {...};

// Batch resolver function for "multiplyByTwo" function
const batchMultiplyByTwo = (inputs: number[]): Promise<number[]> => {...};

const multiplyByTwoBatcher: (input: number) => Promise<number> =
  MicroBatcher<number, number>(multiplyByTwo)
    .batchResolver(batchMultiplyByTwo)
    .build();
Example 2: Multiple Parameters Function
// Original function
const multiply = (input1: number, input2: number): Promise<number> => {...};

// Batch resolver function for "multiply" function
const batchMultiply = (inputs: [number, number][]): Promise<number[]> => {...};

const multiplyBatcher: (input1: number, input2: number) => Promise<number> =
  MicroBatcher<[number, number], number>(multiply)
    .batchResolver(batchMultiply)
    .build();
Example 3: Override Default Batching Interval

The default batching interval is 50ms, which can be overridden using batchingIntervalInMs in the batch options.

const multiplyBatcher: (input1: number, input2: number) => Promise<number> =
  MicroBatcher<[number, number], number>(multiply)
    .batchResolver(batchMultiply, {
      batchingIntervalInMs: 100
    })
    .build();
Example 4: Specify Payload Window Size Limit

By default, Micro Batcher accumulates all caller payloads based on the batching interval.

However, an optional batch option payloadWindowSizeLimit can specify the upper limit of the accumulation size.

Upon reaching the limit, the payloads are immediately delegated to the batch resolver.

const multiplyBatcher: (input1: number, input2: number) => Promise<number> =
  MicroBatcher<[number, number], number>(multiply)
    .batchResolver(batchMultiply, {
      payloadWindowSizeLimit: 5
    })
    .build();

Development

Local Development

pnpm install

Build

pnpm run build

Test

# Run tests
pnpm run test

# Run tests with coverage report
pnpm run test:coverage

# Watch mode
pnpm run test:dev

Roadmap

Features

  • [ ] API Cancellation
  • [ ] Concurrent Batcher Limit Support
  • [ ] Rate Limiting and Throttling Policies Support

Contributing

Contributing

Code of Conduct

Support

License

Micro Batcher is Apache Licensed.

Contact

GitHub Issues: https://github.com/blackrock/micro-batcher/issues