Skip to content

A tiny version of Golang's WaitGroup for Deno with promises and zero dependencies.

Notifications You must be signed in to change notification settings

jpwilliams/waitgroup-deno

Folders and files

NameName
Last commit message
Last commit date

Latest commit

aaa2b3b Β· Jun 18, 2020

History

5 Commits
Jun 18, 2020
Jun 18, 2020
Jun 18, 2020
Jun 18, 2020
Jun 18, 2020
Jun 18, 2020

Repository files navigation

waitgroup

A tiny version of Golang's WaitGroup for Deno with promises and zero dependencies outside of std.

import { WaitGroup } from "https://deno.land/x/waitgroup/mod.ts";

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
  fetch(url).then(() => {
    // Decrement the counter when the GET is complete
    wg.done();
  });
});

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

For most applications, 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 for a Node.js version.

About

A tiny version of Golang's WaitGroup for Deno with promises and zero dependencies.

Resources

Stars

Watchers

Forks

Packages

No packages published