Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@jpwilliams/waitgroup

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jpwilliams/waitgroup

A tiny version of Golang's WaitGroup with typings, promises, and zero dependencies.

  • 2.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

@jpwilliams/waitgroup

npm version Test on push Downloads

A tiny version of Golang's WaitGroup for Node.js and the browser with typings, promises, and zero dependencies.

npm install @jpwilliams/waitgroup
import http from "http";
import { WaitGroup } from "@jpwilliams/waitgroup";

async function main() {
  const wg = new WaitGroup();

  const urls = [
    "http://www.golang.org/",
    "http://www.google.com/",
    "http://www.somestupidname.com/",
  ];

  urls.forEach((url) => {
    // Increment the WaitGroup counter
    wg.add(1);
    // Fetch the URL
    http.get(url, () => {
      // Decrement the counter when the GET is complete
      wg.done();
    });
  });

  // Wait for all HTTP fetches to complete
  await wg.wait();
}

main();

For most applications in Node.js, using built-ins like Promise.all will work perfectly, but sometimes this can be a really nice abstraction if the promises you have to keep track of are pretty spread out.

See jpwilliams/waitgroup-deno for a Deno version.

Keywords

FAQs

Package last updated on 12 Mar 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc