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

sync-looper

v1.0.0

Published

Waits until a long function ends

Readme

sync-looper

This is useful when you want to sample an asynchronious response until it completes. For example, you want to test a module that asynchroniously writes logs. In your test you are expecting to find a specific log entry.

How does it Work

You need to wrap your sampling function with an iterator. This iterator returns 3 states, each leads to a different outcome:

  • when the iterator returns data the loop stops and returns that data
  • when the iterator returns an error the loop stops and returns that error
  • when the iterator returns neither data nor error the loop continues

When the loop reaches maximum repetitions it ends with an error.

Install

$ npm install --save sync-looper

Usage

This module has two classes:

  • The Callback Looper that works with first-error callback functions.
  • The Async Looper that works with async functions

Callback Looper Example:

const { CallbackLooper } = require("sync-looper");
const callbackLooper = new CallbackLooper();
	
let response = null;

// mock an async task that takes 3000 milliseconds
setTimeout(() => {
    response = "data";
}, 3000);

callbackLooper.constWait(
    (repetition, next) => {
        console.info(`repetition ${repetition} for longFunction`);

        if (response == null) return next(); // The response completed and contains the data I expected
        else if (response == "data") return next(null, response); // The response did not complete yet
        else return next("error"); // The response completed with an error
    },
    1000, // wait 1000 milliseconds before repeat
    4, // no more than 4 repetitions
    (err, data) => {
        if (err) console.error(err); // The loop ended with error
        else console.log(data); // The loop ended with the expected data
    }
);

Async Looper Example:

const { AsyncLooper } = require("sync-looper");
const asyncLooper = new AsyncLooper();

let response;

// mock an async task that takes 3000 milliseconds
setTimeout(() => {
    response = "data";
}, 3000);

const run = async () => {
    try {
        const data = await asyncLooper.constWait(
            async repetition => {
                console.info(`repetition ${repetition} for longFunction`);

                if (response == null) return null; // The response completed and contains the data I expected
                else if (response == "data") return response; // The response did not complete yet
                else throw new Error("error"); // The response completed with an error
            },
            1000, // wait 1000 milliseconds before repeat
            4 // no more than 4 repetitions
        );

        console.log(data); // The loop ended with the expected data
    }
    catch (err) {
        console.error(err); // The loop ended with error
    }
}

run();