time-queues is a lightweight ESM JavaScript library for async task scheduling and concurrency control: time-based schedulers, idle/frame/limited queues, throttle, debounce, batch, page lifecycle watchers, and random delays. Works in browsers, Node.js, Bun, and Deno. One runtime dependency: list-toolkit.
For contributor setup and workflow see CONTRIBUTING.md. For detailed usage docs and API references see the wiki.
git clone --recurse-submodules https://github.com/uhop/time-queues.git
cd time-queues
npm installnpm test— run the full test suite (tape-six)node tests/test-<name>.js— run a single test file directlynpm run test:bun— run with Bunnpm run test:deno— run with Denonpm run ts-check— TypeScript type checking (tsc --noEmit)npm run js-check— JS lint via TypeScript (tsconfig.check.json: unused vars / undeclared refs / missing returns / unreachable code)npm run ts-test— run TS typing testsnpm run lint— Prettier format checknpm run lint:fix— Prettier auto-format
Tests use tape-six. JS tests (tests/test-*.js) cover functionality; TS tests (ts-tests/test-*.ts) cover typing only. See node_modules/tape-six/TESTING.md for the full testing API and patterns.
- ESM-only. The project is
"type": "module". - Hand-written
.d.tsfiles. They are NOT generated. When modifying a public API, update both the.jsand.d.tsfiles. - Do not modify or delete test expectations without understanding why they changed.
- Do not add comments or remove comments unless explicitly asked.
- Prettier: 100 char width, single quotes, no bracket spacing, no trailing commas, arrow parens "avoid" (see
.prettierrc). - 2-space indentation.
- PascalCase classes (
MicroTask,ListQueue), camelCase functions (defer,sleep). - Files match export names:
MicroTask.js,defer.js. - All modules export both named and default.
- Private fields use
#prefixwith getters for read-only access. Promise.withResolvers()preferred; manualPromisefallback where needed.- Run
npm run lint:fixbefore completing work.
MicroTask (single task with promise support)
└─ Task (Scheduler-specific, adds delay/time)
MicroTaskQueue (abstract queue base)
├─ Scheduler (time-based, uses min-heap)
└─ ListQueue (linked-list storage)
├─ IdleQueue (requestIdleCallback)
├─ FrameQueue (requestAnimationFrame)
├─ LimitedQueue (concurrency control)
└─ PageWatcher (page lifecycle events)
Standalone: Counter, Throttler, Retainer, CancelTaskError
- Lazy Promise Creation — promises are only created when
.makePromise()is called or viaschedule(). - Clean Cancellation — all tasks support cancellation via
CancelTaskError. - Graceful Degradation — feature detection, not environment sniffing.
- Memory Efficiency — linked lists and heaps, not arrays.
- Source:
src/<Name>.js+src/<Name>.d.ts(classes) orsrc/<name>.js+src/<name>.d.ts(functions) - Tests:
tests/test-*.js,tests/test-*.mjs,tests/test-*.cjs - TS typing tests:
ts-tests/test-*.ts - Wiki docs:
wiki/(git submodule) - Technical docs:
ARCHITECTURE.md,CONTRIBUTING.md
- Start with
src/MicroTask.js→src/MicroTaskQueue.js→src/ListQueue.jsto understand the class hierarchy. .d.tsfiles are the best API reference for each module.- Wiki markdown files in
wiki/contain detailed usage docs. ARCHITECTURE.mdhas the full design deep-dive.