limit-queue
TypeScript icon, indicating that this package has built-in type declarations

0.0.6 • Public • Published

Travis CI David npm The MIT License

NPM

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 poolMs
  • poolMs: If the cap is reached, wait for poolMs milliseconds

Test

npm test

Package Sidebar

Install

npm i limit-queue

Weekly Downloads

4

Version

0.0.6

License

MIT

Last publish

Collaborators

  • havsar