# limit-queue

> Limit function calls with a timeout. Useful for rate limiting against services (e.g. TMDB). Supports promises.

Latest version **0.0.6** (published 2017-03-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install limit-queue
pnpm add limit-queue
yarn add limit-queue
bun add limit-queue
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.6 |
| Published | 2017-03-26 |
| First published | 2017-03-16 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Himmet Avsar |
| Maintainers | havsar |
| Keywords | node, queue, limit, ratelimit, promise, async |

## Links

- npm: https://www.npmjs.com/package/limit-queue
- Repository: https://github.com/havsar/limit-queue
- Homepage: https://github.com/havsar/limit-queue#readme
- Issues: https://github.com/havsar/limit-queue/issues
- npm.io page: https://npm.io/package/limit-queue

## Alternatives

- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads
- [fa](https://npm.io/package/fa.md) — 185 weekly downloads

## Recent versions

- 0.0.6 (latest) — 2017-03-26
- 0.0.5 — 2017-03-24
- 0.0.4 — 2017-03-24
- 0.0.3 — 2017-03-16
- 0.0.2 — 2017-03-16

## README

[![Travis CI](https://img.shields.io/travis/havsar/limit-queue.svg)](https://travis-ci.org/havsar/limit-queue) 
[![David](https://img.shields.io/david/havsar/limit-queue.svg)](https://david-dm.org/havsar/limit-queue)
[![npm](https://img.shields.io/npm/v/limit-queue.svg)](https://www.npmjs.org/package/limit-queue)
[![The MIT License](https://img.shields.io/npm/l/limit-queue.svg)](http://opensource.org/licenses/MIT)

[![NPM](https://nodei.co/npm/limit-queue.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/limit-queue/)

# limit-queue
Limit function calls with a timeout. Useful for rate limiting against services (e.g. TMDB). Supports promises.

<!-- TOC depthTo:2 -->

- [limit-queue](#limit-queue)
- [Install](#install)
- [Usage](#usage)
- [RateLimitQueue](#ratelimitqueue)
- [Test](#test)

<!-- /TOC -->

# Install
```bash
npm install --save limit-queue
```
or
```bash
yarn add limit-queue
```

# Usage
With promises or async/await
```ts
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
```bash
npm test
```

---
_Source: https://npm.io/package/limit-queue · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
