limit-queue
v0.0.6
Published
Limit function calls with a timeout. Useful for rate limiting against services (e.g. TMDB). Supports promises.
Downloads
38
Maintainers
Readme
limit-queue
Limit function calls with a timeout. Useful for rate limiting against services (e.g. TMDB). Supports promises.
Install
npm install --save limit-queue
or
yarn add limit-queue
Usage
With promises or async/await
import { RateLimitQueue } from "limit-queue";
const queue = new RateLimitQueue(1, 5000);
async function doSomething(): Promise<void> {
// Pool will start on first call
await queue.limit(function () {
return "Response One";
});
await queue.limit(function () {
return MyService.getUsers();
});
console.log("Done");
}
RateLimitQueue
Use this Queue as rate limit pool. cap function calls are allowed within poolMs milliseconds.
cap
: Amount of function calls within poolMspoolMs
: If the cap is reached, wait for poolMs milliseconds
Test
npm test