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

ts-waitgroup

v1.0.0

Published

A WaitGroup waits for a collection of async functions to finish

Downloads

1

Readme

ts-waitgroup

Continuous Integration Status

A WaitGroup waits for a collection of async functions to finish.

This module simulates the working of the WaitGroup type of the sync package of the Go programming language.

The module implements a WaitGroup class, that waits for a collection of asynchronous function to finish.

The main function, that uses the WaitGroup initializes its counter or, calls the add() method to set the number of async functions to wait for. Then each of the async functions runs and calls done() when finished. The done() function must be called as many times the counter was set to. At the same time, wait() can be used to block until all async functions have finished. The done() calls may have a result: any parameter. In this case the parameter of the last done() call will be the return value of the wait() function.

If there is a problem, the fail() call will break the execution, so the wait() will return immediately with the optional result: any parameter that was given to the fail() call.

Usage

    // Start a wait-group with more than one items
    const wg = new WaitGroup(3);

    // Start async function-1
    setTimeout(() => {
        wg.done('OK');
    }, 10);

    // Start async function-2
    setTimeout(() => {
        wg.done('OK');
    }, 20);

    // Start async function-3
    setTimeout(() => {
        wg.done('OK');
    }, 30);

    // Wait for the completion of the async functions
    const result = await wg.wait();
    // result = 'OK'

See the unit tests for more examples.

See also the API docs.

Development

It uses the following tools:

Build

To compile TypeScript code use the following command:

task build

This will create a "dist" folder in which all the compiled JavaScript files appear.

Run lint

This project uses ESLint with Prettier, Airbnb and recommended TypeScript configurations. In order to start lint locally, use this command:

task lint

Test with coverage

Test files can be found beside the corresponding source files. Every test file name must follow the "*.test.ts" pattern. To run these tests and generate coverage report, use this command:

task test

The generated coverage report can be found under the "coverage" folder.

Clean project

To remove the "build" and "coverage" folders you can run the clean command.

task clean

License

The code and documentation in this project are released under the MIT License