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 🙏

© 2024 – Pkg Stats / Ryan Hefner

autobatch-promise

v1.0.0

Published

Automatically split work into batches. A promise-based concurrency primitive.

Downloads

5

Readme

Automatic batching of work based on Promises

Sometimes work can be done quicker in batches (e.g. inserting multiple rows into a database in one transaction, or making a request to a remote server that supports batch requests). This package helps to automatically collect individual calls (items of work) into batches.

While one batch is busy being flushed, another batch is prepared in background to be flushed next. Error handling resizes batches to find and prune any items that cause errors.

Order of items is always preserved.

Usage

const Autobatch = require('autobatch');
const batch = new Autobatch(flushCallback, {onError, maxBatchSize, maxQueueSize})
…
batch.add("item1");
batch.add("item2");
batch.add("item3");

new Autobatch(cb, options)

  • flushCallback(batchArray) — function receiving an array if items to flush. If it throws an error when the batch contains more than one item, the items will be flushed again in a smaller batch.
  • options:
    • onError(error, item) — callback called whenever the flushCallback failed to flush the item.
    • maxBatchSize — maximum number of items to flush in one go. 0 (the default) means no limit.
    • maxQueueSize — maximum number of items stored and waiting to be flushed. When there are more items than this limit, some items will be dropped. 0 (the default) means no limit (other than Node running out of memory).

autobatch.add(item, [ item… ])

Queues all arguments as items to be flushed. The items can be any JS value. They will be passed as-is to the flushCallback.

Returns a Promise which will resolve when all items are flushed. It never returns errors.

autobatch.flush()

Waits until all items are flushed. It never returns errors. It's not necessary to call this function, since add() flushes as well.