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 🙏

© 2026 – Pkg Stats / Ryan Hefner

super-loop

v0.3.1

Published

Producer-consumer implementation based on nodejs stream

Downloads

72

Readme

NPM

Super Loop

Easy programming interface for producer-consumer problem and enhanced loop, leveraging nodejs stream.

It provides the following features:

  • repeats cycle for n times;
  • repeats cycle until future moment;
  • repeats cycle until "ender" function returns true;
  • supports tps controlling;
  • supports backpressure;
  • supports max concurrency configuration;

Why

Asynchronous event-based processing is quite common in modern microservice architecture as well as data ETL. Here are some typical use cases:

  • Consume SQS messages at given max tps and max concurrency to fully utilize system capacity (e.g. CPU);
  • Read upstream events and persist them to a NoSQL db at fast and controlled pace;
  • Purge NoSQL db records selectively at fast and controlled pace;
  • Process CSV files and call REST API at fast and controlled pace;
  • Performance-test HTTP endpoints with customized data, i.e. a simplified version of K6;

The goal of this library is to provide easy programming interfaces for those common and popular use cases, so as to increase developer efficiency.

Installation

npm i --save super-loop

Usage Examples

Example - producer consumer problem

const SuperLoop =  require('super-loop');
const stats = require('measured-core').createCollection();

async function main() {
    const intv = setInterval(function () {
        console.log(JSON.stringify(stats, null, 2));
    }, 1000);

    try {
        const producer = () => {
            stats.meter('producerTps').mark();
            return [{name: 'John'}, {name: 'Alex'}]
        }

        const consumer = (data) => {
            stats.meter('consumerTps').mark();
            // processing ...
            //console.log(data);
        }

        const loop = new SuperLoop();
        const lastFor = 120_000;

        loop.on('warn', (err) => {
            console.error(err);
        });

        await loop.producedBy(producer)
            .consumedBy(consumer)
            .concurrency(200)
            .rate(1000)
            //.repeat(100)
            .until(Date.now() + lastFor)
            .exec();

        console.log('loop ends')

    } catch (e) {
        console.error('something went wrong', e)
    }
    clearInterval(intv);
}

main().catch(console.error)

More examples

API

Super Loop API design follows Fluent Interface. All methods return this, except exec which kicks off the execution of the loop.

consumedBy(func)

Configure consumer function.

Arguments:

  • func is a function that take nodejs stream chunk as param, and returns nothing. e.g. (data) => { console.log(data) }

producedBy(func)

Configure producer function.

Arguments:

  • func is a function that takes no param, but returns an Array of data chunks. e.g. () => [1, 2, 'a', 'b']

invoke(func)

Alias to consumedBy.

endedBy(func)

Configure ender function. When the ender function returns true, the loop ends. e.g. () => false

Arguments:

  • func is a function that takes no param, but returns a boolean.

concurrency(maxC)

Configure max concurrency for consumer function.

Arguments:

  • maxC is the max concurrecy the consumer function would run at.

rate(tps)

Configure max tps for consumer function.

Arguments:

  • tps is the max tps the consumer function would run at.

until(endTime)

Configure timestamp (in ms) when the loop should stop.

Arguments:

  • endTime timestamp in ms

repeat(times)

Configure max repeats the producer function should be called. After max repeats are reached, loop ends.

Arguments:

  • times max repeats

pipeFrom(upstream)

Configure custom upstream rather than using super-loop internal Readable as upstream.

A good example is processing file stream.

Arguments:

  • upstream Transform or Readable stream

pipeTo(downstream)

Configure custom downstream to continue streaming.

Arguments:

  • downstream Transform or Writable stream

exec()

Start the loop for execution, until one of the ending conditions is met. The ending conditions are specified by endedBy, until, repeat.

Returns:

  • Error if critical error happens in the internal nodejs streams

Events

  • warn. The loop emits non-critical errors when processing individual data chunks. Here is an example to catch them and log them properly:
loop.on('warn', (err) => {
    myLogger.error(err);
});

License

super-loop is licensed under the MIT license.