Registry / devops / smart-request-balancer

smart-request-balancer

JSON →
library2.2.0jsnpmunverified

Smart request balancer with fine tuning of rates and limits of queue execution. Current stable version is 2.2.0. This library allows developers to define multiple rate-limiting rules per resource, with per-key granularity and automatic retry support. It provides priority-based queueing, overall and default limits, and an ignoreOverallOverheat option. Written in TypeScript with full type definitions. Compared to similar libraries like bottleneck or p-limit, it offers more flexible rule configuration and built-in retry mechanism. Release cadence is irregular; last update was in 2021.

npm install smart-request-balancer
INSTALL
IMPORT
SIG · SMART-REQUEST-BALA
S
smart-request-balancer
devopsjavascriptv2.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.

Queue
import Queue from 'smart-request-balancer'
import { Queue } from 'smart-request-balancer'
This library uses a default export. In TypeScript or ESM, import the default. CommonJS requires the module itself.
Queue
const Queue = require('smart-request-balancer')
CommonJS usage. No destructuring needed.
Queue
const Queue = require('smart-request-balancer').default
const Queue = require('smart-request-balancer')
In TypeScript with esModuleInterop false, you might need to use .default. Check your TS config.

Creates a queue with custom rules and makes a request with retry on 429.

import Queue from 'smart-request-balancer'; const queue = new Queue({ rules: { common: { rate: 30, limit: 1, priority: 1 } }, default: { rate: 30, limit: 1 }, overall: { rate: 30, limit: 1 }, retryTime: 300 }); async function makeRequest() { const result = await queue.request( (retry) => fetch('https://api.example.com/data') .then(res => res.json()) .catch(err => { if (err.status === 429) { return retry(5000); } throw err; }), 'user-123', 'common' ); console.log(result); } makeRequest();
Debug
Known issues
gotchaThe 'default' option in Queue constructor is misspelled as 'default' but the README shows 'default'. Actually the option key is 'defaults'? Check documentation.
fix
Use the configuration object as described in the README; no fix needed.
affects: >=2.0.0
breakingIn version 2.0.0, the API changed from a class instantiation to a constructor that takes a configuration object. Old versions used a different pattern.
fix
Upgrade to 2.0.0 or higher and use the new configuration object format.
affects: <2.0.0
deprecatedThe 'ignoreOverallOverheat' option is not documented as deprecated, but may be removed in future versions.
fix
Avoid using ignoreOverallOverheat if possible, or monitor for future changes.
affects: >=2.0.0
Errors
Common errors & fixes
Cannot find module 'smart-request-balancer'
Package not installed or import path wrong.
fix
Run 'npm install smart-request-balancer' and ensure import uses default export.
TypeError: queue.request is not a function
Queue instance not created correctly, possibly due to incorrect import.
fix
Use 'import Queue from "smart-request-balancer"' or 'const Queue = require("smart-request-balancer")' and then instantiate with 'new Queue({...})'.
TypeError: (intermediate value).then is not a function
The first argument to queue.request must be a function that returns a promise, but a non-function or non-promise was provided.
fix
Ensure the first argument is a function like '(retry) => fetch(...).then(...).catch(...)'.
Upgrade
Version history
2.2.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
Resources
smart-request-balancer — npm install smart-request-balancer · libregistry