Zero-dependency async tiny task queue and utilities
Find a file
2026-02-03 05:04:25 +00:00
.helix fix vscode-json-language-server formatting behavior 2026-02-03 05:04:25 +00:00
src split source files based on contents 2026-02-02 18:32:30 +00:00
.gitignore init repo 2026-02-02 07:36:59 +00:00
eslint.config.ts add lint config 2026-02-02 18:12:18 +00:00
jest.config.js add basic unit test 2026-02-02 07:57:44 +00:00
LICENSE init repo 2026-02-02 07:36:59 +00:00
mise.toml add lint config 2026-02-02 18:12:18 +00:00
package-lock.json add lint config 2026-02-02 18:12:18 +00:00
package.json add lint config 2026-02-02 18:12:18 +00:00
README.md init repo 2026-02-02 07:36:59 +00:00
rollup.config.mjs init repo 2026-02-02 07:36:59 +00:00
tsconfig.json init repo 2026-02-02 07:36:59 +00:00

Attq!

An async tiny task queue (and related utilities), with zero dependencies. Attq provides a data structure that executes an asynchronous callback sequentially on a flexible list. It is designed to facilitate in-order client-server message passing with bells and whistles including batching, throttling, and configurable retries. Work in progress.

Example

import { AsyncTaskQueue } from "attq";

const q = new AsyncTaskQueue<number>(
  (nums: number[]) => fetch(`/refine?macrodata=${nums.join(",")}`),
)
  // Handler will receive up to 4 items per batch.
  .batchSize(4)
  // Handler will be called at most once per 100 milliseconds.
  .throttleMs(100);

// Add items to the queue.
for (let n = 0; n < 1000; n++) {
  q.push(n);
}

await new Promise((resolve) => setTimeout(resolve, 5000));

console.log(q.size()); // Should display >=800 items remaining.

// Stop processing items if any causes an exception.
q.onError(() => {
  q.drain();
});