Q
Simple queue task runner written in typescript
Install / Use
/learn @phil-r/QREADME
Q
Simple queue task runner written in typescript
Usage
import { queue } from 'https://deno.land/x/q/mod.ts';
let result = 0;
const task = (a: number) => (result += a);
const q = queue(task, 2); // 2 is concurrency
q.drain(() => {
console.log(`Result: ${result}`);
}); // will log `Result: 6`
q.push(1);
q.push([2, 3]);
or using async/await
import { queue } from 'https://deno.land/x/q/mod.ts';
let result = 0;
const task = (a: number) => (result += a);
const q = queue(task, 2); // 2 is concurrency
q.push(1);
q.push([2, 3]);
await q.drain();
console.log(`Result: ${result}`); // will log `Result: 6`
it's also possible to use onDone and onError callbacks
import { queue } from 'https://deno.land/x/q/mod.ts';
let result = 0;
const task = (a: number) => {
if (a === 4) throw Error('ow no');
return (result += a);
};
const q = queue(task, 2); // 2 is concurrency
q.push([1, 2, 3, 4]);
q.onDone((task, result) =>
console.log(`For task: ${task}, result is ${result}`)
);
/*
Will log:
For task: 1, result is 1
For task: 2, result is 3
For task: 3, result is 6
*/
q.onError((task, error) => console.error(`Task: ${task} failed with ${error}`));
// Will log: Task: 4 failed with Error: ow no
await q.drain();
console.log(`Result: ${result}`); // will log `Result: 6`
Run tests
deno test
Related Skills
node-connect
349.0kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
109.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.
Writing Hookify Rules
109.4kThis skill should be used when the user asks to "create a hookify rule", "write a hook rule", "configure hookify", "add a hookify rule", or needs guidance on hookify rule syntax and patterns.
review-duplication
100.3kUse this skill during code reviews to proactively investigate the codebase for duplicated functionality, reinvented wheels, or failure to reuse existing project best practices and shared utilities.
