Registry / devops / ready-queue

ready-queue

JSON →
library1.0.0jsnpmunverified

A lightweight Node.js library (v1.0.0) that ensures an initialization function runs only once for a given set of arguments, while queuing and resolving multiple listeners that register before the function completes. Provides built-in retry support on failure. Ideal for deduplicating async operations like data fetching or resource initialization.

npm install ready-queue
INSTALL
IMPORT
SIG · READY-QUEUE
R
ready-queue
devopsjavascriptv1.0.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.

queue
✓ const queue = require('ready-queue')
✗ import queue from 'ready-queue'
This package is CommonJS only. Using ES import may fail in default Node.js environments.
ReadyQueue
✓ const queue = require('ready-queue')
✗ import { ReadyQueue } from 'ready-queue'
No named exports exist. The package exports a single function.
default export
✓ const queue = require('ready-queue')
✗ const { default: queue } = require('ready-queue')
CommonJS require returns the function directly, not as a default property.

Creates a queue that deduplicates calls to load with the same arguments and queues listeners until the promise resolves.

const queue = require('ready-queue'); const q = queue({ load: (userId) => { // Simulate async fetch (returns promise) return Promise.resolve({ id: userId, name: 'User' + userId }); }, retry: 1 }); q.add(123).then(user => { console.log(user); // First call triggers load(123) }); q.add(123).then(user => { // Same arguments, load is not called again }); q.add(456).then(user => { // Different arguments triggers new load(456) });
Debug
Known issues
gotchaThe load function must return a Promise or a synchronous value. If it returns undefined, the queue will resolve immediately with undefined.
fix
Ensure load returns a promise if async, or a truthy value if sync.
affects: >=1.0.0
gotchaThe .add() method returns a Promise that resolves with the result of load. It does not support cancellation or timeout.
fix
Implement your own timeout wrapper around the queue if needed.
affects: >=1.0.0
gotchaThis package has no TypeScript type definitions. Using it in TypeScript may require custom type declarations.
fix
Create a .d.ts file: declare module 'ready-queue';
affects: >=1.0.0
gotchaThe 'retry' option integer specifies number of retries on failure, but does not implement exponential backoff.
fix
Implement your own retry logic with backoff if needed.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: queue is not a function
Using ES import (import queue from 'ready-queue') on this CommonJS-only package may result in undefined.
fix
Use require('ready-queue') instead of import.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
12 hits · last 30 days
node
10
Resources