gitmyhub

waitgroup.js

JavaScript ★ 52 updated 10y ago

Go style WaitGroup for JS-land

A tiny JavaScript helper that lets your code wait for multiple concurrent tasks to finish before moving on, inspired by Go's WaitGroup pattern.

JavaScriptNode.jssetup: easycomplexity 2/5

WaitGroup is a tiny JavaScript helper that lets your code wait for several tasks to finish before moving on. If you've ever kicked off multiple operations at once and needed to know when all of them were done, this is for you.

The concept comes from Go, where a "WaitGroup" is a standard way to track concurrent work. The idea is simple: you add a count for each task you're starting, each task signals when it's done, and the wait function blocks until that count reaches zero. This library brings that same pattern to JavaScript.

Who would use this? Say you're building a script that fetches data from five different APIs at the same time. You want to wait until all five have returned before processing the results together. Instead of manually juggling counters or callbacks, you'd use this library to add five tasks, mark each one as it completes, and call wait to pause until everything finishes.

The README doesn't go into detail beyond the basics. There's no usage examples, no API documentation, and no explanation of edge cases. What you get is a minimal implementation of the concept, which is consistent with the project's tiny footprint. If you're comfortable reading source code or already know how Go's WaitGroup works, you'll pick it up quickly. If not, you may need to experiment a bit to understand the exact method names and behavior.

Where it fits