Gosync
Go-style channel and waitGroup for js to handle task queue.
Install / Use
/learn @stanNthe5/GosyncREADME
goSync
Go-style channel and waitGroup for nodejs.
Why
I made this so that I can control task queue more easily. I guess there will be other use cases.
Install
npm i gosync
Usage
channel
import { channel } from 'gosync';
let ch = new channel<number>();
(async () => {
for (let i = 1; i <= 5; i++) {
let num = await ch.take()
console.log('taken', num)
}
})();
(async () => {
for (let i = 1; i <= 5; i++) {
await new Promise(resolve => setTimeout(resolve, 1000))
console.log('adding ', i)
await ch.add(i)
}
})();
channel and waitGroup
import { channel, waitGroup } from 'gosync';
// Execute 20 tasks with a maximum of 5 concurrent tasks
const ch = new channel<null>(5);
const wg = new waitGroup();
console.time('total');
for (let i = 1; i <= 20; i++) {
wg.add(1);
await ch.add(null);
(async () => {
await someAsyncTask(i.toString());
await ch.take();
wg.done();
})();
}
await wg.all();
console.timeEnd('total');
function someAsyncTask(id: string) {
return new Promise((resolve, reject) => {
setTimeout(() => {
console.log(`finished ${id}`);
resolve(1);
}, Math.random() * 1000 + 500);
});
};
Related Skills
node-connect
340.5kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
84.2kCreate 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
340.5kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
84.2kCommit, push, and open a PR
