Registry / devops / async-interval-queue

async-interval-queue

JSON →
library1.0.9jsnpmunverified

A lightweight, zero-dependency job scheduler that runs async tasks at fixed intervals. Version 1.0.9 is the current stable release; the package is mature and used in production, but the GitHub repo shows low maintenance activity. It supports automatic retries on failure, a decorator pattern for wrapping functions, and simple thunk-based job submission. Unlike full-featured job queues (e.g., Bull, Agenda), it has no persistence, clustering, or advanced scheduling; its simplicity makes it ideal for rate-limiting API calls in single-process applications. A sharded version is available separately.

npm install async-interval-queue
INSTALL
IMPORT
SIG · ASYNC-INTERVAL-QUE
A
async-interval-queue
devopsjavascriptv1.0.9
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

AsyncQueue
const AsyncQueue = require('async-interval-queue');
import AsyncQueue from 'async-interval-queue';
Package provides only a CommonJS default export. ESM import will fail unless using a bundler that can handle CJS.
new AsyncQueue(intervalMs)
const queue = new AsyncQueue(1000);
const queue = AsyncQueue(1000);
Must be instantiated with 'new'. The constructor expects a numeric interval in milliseconds.
queue.add(thunk, doNotStart?, retries?)
queue.add(() => fetch(url), false, 3);
queue.add(fetch(url), false, 3);
First argument must be a function returning a promise, not a promise itself. This is the thunk pattern.

Creates a queue with 1s interval, adds a job with retry, and logs the result.

const AsyncQueue = require('async-interval-queue'); const queue = new AsyncQueue(1000); // 1 second interval async function fetchData(id) { return `Data for ${id}`; } // Add job with retries (up to 3 attempts) queue.add(() => fetchData(1), false, 3).then(console.log).catch(console.error); // Queue starts automatically // Output after ~1s: Data for 1
Debug
Known issues
gotchaThe queue stops when empty; adding a job with doNotStart=true will not restart it.
fix
Call queue.start() manually after adding jobs with doNotStart=true, or add without doNotStart to auto-start.
affects: >=1.0.0
gotchaThe decorator method wraps the function but changes its context; 'this' may not work as expected.
fix
Use arrow functions or bind the original function before decorating if 'this' is needed.
affects: >=1.0.0
gotchaIf a job's thunk throws synchronously (not a rejected promise), the queue may crash.
fix
Always return a promise from the thunk; wrap sync code in Promise.resolve().
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: AsyncQueue is not a constructor
Using ESM import (import AsyncQueue from 'async-interval-queue') which is not supported.
fix
Use CommonJS require: const AsyncQueue = require('async-interval-queue');
TypeError: queue.add is not a function
Forgetting to instantiate with 'new', or importing incorrectly.
fix
Ensure you have an instance: const queue = new AsyncQueue(1000);
UnhandledPromiseRejectionWarning: Error: Thunk must return a Promise
Passing a promise directly instead of a function that returns a promise.
fix
Wrap the promise in an arrow function: queue.add(() => myPromise, ...);
Upgrade
Version history
1.0.9latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
9 hits · last 30 days
node
8
OpenAI (training)
1
Resources
async-interval-queue — npm install async-interval-queue · libregistry