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

debouncing-batch-queue

v1.0.3

Published

A queue which will emit and clear its contents when its size, timeout, or both are reached

Readme

Debouncing batch queue

A queue which will emit and clear its contents when its size or timeout is reached. Ideal for aggregating data for bulk apis where batching in a timely manner is best. Or anything really where batching data is needed.

Namespaces can be used to utilize multiple internal queues with each maintaining its own debounce timer and max batch size threshold.

Installation

npm i -S debouncing-batch-queue

Usage

Simple:

const DBBQ = require('debouncing-batch-queue');
const dbbq = new DBBQ(1000, 2);  // 1000ms debounce timeout and max batch size of 2
 
dbbq.on('data', (data) => {
  console.log('Data:', data);
});
 
dbbq.add('ribs 0');
dbbq.add('ribs 1');
dbbq.add('ribs 2');
 
// log...
// Data: [ 'ribs 0', 'ribs 1' ]  <-- reached max size and emitted immediately
// Data: [ 'ribs 2' ]            <-- was below max size and emitted after timeout

More complex with namespaces:

const DBBQ = require('debouncing-batch-queue');
const dbbq = new DBBQ(1000, 2);  // 1000ms debounce timeout and max batch size of 2
 
dbbq.on('data', (data, namespace) => {
  console.log('Data:', data, 'Namespace:', namespace);
});
 
dbbq.add('ribs 0');
dbbq.add('ribs 1');
dbbq.add('ribs 2');
dbbq.add('ribs 3');
dbbq.add('ribs 4');
dbbq.add('more ribs', 'bbq1');
dbbq.add('more ribs', 'bbq1');
dbbq.add('brisket', 'best bbq namespace');
 
// log...
// Data: [ 'ribs 0', 'ribs 1' ] Namespace: undefined   <-- reached max size and emitted immediately
// Data: [ 'ribs 2', 'ribs 3' ] Namespace: undefined   <-- reached max size and emitted immediately
// Data: [ 'more ribs', 'more ribs' ] Namespace: bbq1  <-- reached max size and emitted immediately
// Data: [ 'ribs 4' ] Namespace: undefined             <-- was below max size and emitted after timeout
// Data: [ 'brisket' ] Namespace: best bbq namespace   <-- was below max size and emitted after timeout

API

#constructor(timeout, maxBatchSize)

timeout

Default: -1

This is the delay in milliseconds for debouncing before the queue will be emitted and cleared. Any number less than 0 is viewed as infinite, i.g. there will never be a timer which will drain the queue.

maxBatchSize

Default: -1

This is the maximum qty of data that the queue will hold before the queue is emitted and cleared. Any number less than 0 is viewed as infinite, i.g. the queue can grow to an unlimited size.


Note: If both parameters are given or resolve to < 0, then the queue will immediately emit and clear after every single data added. This is to prevent the queue in this configuration to never emit and clear.

#add(data, namespace)

data

required

This is what will be added to the queue.

namespace

optional

When calling #add(data, namespace), each namespace (or the default of no namespace given) is treated as a separate queue. Each namespace maintains its own debouncing timeout and maxBatchSize for the data it contains.

#instance.on('data', (data, namespace) => {})

onData is the event to listen for when the queue is being cleared. The queue clears itself when the debouncing timeout fires or it has reach it maximum capacity.

data

Data is an array where each entry within it contains whatever was given from each #add(data) call before the event is fired. The order of the #add(data) calls is maintained in the emitted data array.

namespace

This is the namespace of the emitted queue. If namespaces are being used, this will be handy to keep track of what namespaced queue has just been emitted.

If the default queue (no namespace) is emitted, this value will be undefined.