Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jpwilliams/waitgroup-deno
A tiny version of Golang's WaitGroup for Deno with promises and zero dependencies.
https://github.com/jpwilliams/waitgroup-deno
Last synced: 22 days ago
JSON representation
A tiny version of Golang's WaitGroup for Deno with promises and zero dependencies.
- Host: GitHub
- URL: https://github.com/jpwilliams/waitgroup-deno
- Owner: jpwilliams
- Created: 2020-06-18T18:37:46.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-06-18T21:38:10.000Z (over 4 years ago)
- Last Synced: 2024-05-02T05:50:09.292Z (6 months ago)
- Language: TypeScript
- Size: 5.86 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# waitgroup
A tiny version of Golang's [WaitGroup](https://golang.org/pkg/sync/#WaitGroup) for Deno with promises and zero dependencies outside of `std`.
```ts
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](https://github.com/jpwilliams/waitgroup) for a Node.js version.