Waitgroup.js
A way of signalling completion of multiple concurrent tasks, similar to the sync.WaitGroup in Go Lang.
Install / Use
/learn @dtjm/Waitgroup.jsREADME
waitgroup.js - concurrency synchronization primitive
This is a translation of Go's sync.WaitGroup for JavaScript, used extensively in TextDrop.
Use this if you want run several asynchronous tasks concurrently and run a function when all the results come back. (E.g. if you want to make multiple web requests or database queries, then use them together).
This is much better than making each request in serial, and takes advantage of JavaScript's asynchronous design to boost the response time of your program by making your requests concurrent.
Usage
var wg = new WaitGroup;
wg.add();
initResource1().on("done", function(){
wg.done();
});
wg.add();
initResource2().on("done", function(){
wg.done();
});
wg.add();
initResource3().on("done", function(){
wg.done();
});
wg.wait(function(){
console.log("All done!")
});
Methods
add()
Increments the WaitGroup counter
done()
Decrements the WaitGroup counter. When the counter becomes 0, the function
passed to wait() will be called.
wait(func)
Registers a callback to be called when all tasks in the WaitGroup are done.
Tests
Run the tests with npm test
Related Skills
node-connect
341.0kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
84.4kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
341.0kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
84.4kCommit, push, and open a PR
