Registry / testing / simple-rate-limited-queue

simple-rate-limited-queue

JSON →
library1.2.0jsnpmunverified

A lightweight rate-limited queue for async operations in Node.js. v1.2.0 (stable, under 1KB gzipped, no dependencies). Limits operations per time interval and concurrent in-progress operations. Key differentiator: simple, minimal API with pause/resume/terminate and optional retry support via higher-order function. Ships TypeScript types. Released as needed; last update recent.

npm install simple-rate-limited-queue
INSTALL
IMPORT
SIG · SIMPLE-RATE-LIMITE
S
simple-rate-limited-queue
testingjavascriptv1.2.0
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.

RateLimitedQueue
✓ import { RateLimitedQueue } from 'simple-rate-limited-queue'
✗ const RateLimitedQueue = require('simple-rate-limited-queue')
ESM-only package; no CommonJS support.
withRetry
✓ import { withRetry } from 'simple-rate-limited-queue'
✗ import withRetry from 'simple-rate-limited-queue'
Named export, not default.
RateLimitedQueue type (TypeScript)
✓ import { RateLimitedQueue } from 'simple-rate-limited-queue//types'
✗ import { RateLimitedQueue } from 'simple-rate-limited-queue'
Types are bundled, no extra path needed; this entry is just to clarify that types are available.

Creates a rate-limited queue, schedules an async fetch operation, and shows retry logic on failure.

import { RateLimitedQueue, withRetry } from 'simple-rate-limited-queue'; const queue = new RateLimitedQueue({ maxPerInterval: 5, maxInProgress: 2, intervalLength: 1000 }); async function fetchUser(id: number): Promise<any> { const response = await queue.schedule(() => fetch(`https://api.example.com/users/${id}`)); return response.json(); } // Usage fetchUser(1).then(console.log).catch(console.error); // With retry const fetchWithRetry = withRetry( (id: number) => fetch(`https://api.example.com/users/${id}`).then(r => r.json()), (err: any, count: number) => count < 3 ? 1000 : undefined ); queue.schedule(() => fetchWithRetry(2)).then(console.log);
Debug
Known issues
gotchaQueue methods (schedule, token) will reject if the queue is terminated. Must handle rejection.
fix
Wrap calls in try/catch or use .catch().
affects: >=1.0.0
gotchaThe queue does not automatically retry operations; use withRetry to implement retries manually.
fix
Use the withRetry helper and provide a shouldRetry callback.
affects: >=1.0.0
gotchaCalling terminate() cancels all queued operations and prevents new ones. Use reset() to reuse the queue after termination.
fix
Call queue.reset() after termination if you need to reuse the queue.
affects: >=1.0.0
Errors
Common errors & fixes
ERR_REQUIRE_ESM: Must use import to load ES Module: /path/to/node_modules/simple-rate-limited-queue/index.js
Attempting to require() the ESM-only package in a CommonJS module.
fix
Use import syntax or convert your project to ESM.
TypeError: queue.schedule is not a function
Importing default instead of named export.
fix
Use import { RateLimitedQueue } from 'simple-rate-limited-queue'.
Error: The queue has been terminated
Trying to schedule an operation after calling terminate() without reset().
fix
Call queue.reset() before scheduling new operations after termination.
Upgrade
Version history
1.2.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
simple-rate-limited-queue — npm install simple-rate-limited-queue · libregistry