# throat

> Throttle the parallelism of an asynchronous (promise returning) function / functions

Latest version **6.0.2** (published 2023-01-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install throat
pnpm add throat
yarn add throat
bun add throat
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 6.0.2 |
| Published | 2023-01-03 |
| First published | 2012-12-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 8.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 481 |
| Author | ForbesLindesay |
| Maintainers | forbeslindesay, throat-bot |
| Keywords | promise, aplus, then, throttle, concurrency, parallelism, limit |

## Links

- npm: https://www.npmjs.com/package/throat
- Repository: https://github.com/ForbesLindesay/throat
- Homepage: https://github.com/ForbesLindesay/throat#readme
- Issues: https://github.com/ForbesLindesay/throat/issues
- npm.io page: https://npm.io/package/throat

## 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

- 6.0.2 (latest) — 2023-01-03
- 6.0.1 — 2021-01-20
- 6.0.0 — 2021-01-20
- 5.0.0 — 2019-05-24
- 4.1.0 — 2017-07-07
- 4.0.0 — 2017-06-20
- 3.2.0 — 2017-06-13
- 3.1.0 — 2017-06-04
- 3.0.0 — 2016-06-01
- 2.0.2 — 2015-02-16
- 2.0.1 — 2015-02-14
- 2.0.0 — 2015-02-14
- 1.0.0 — 2013-07-27
- 0.0.0 — 2012-12-23

## README

# throat

Throttle the parallelism of an asynchronous, promise returning, function / functions. This has special utility when you set the concurrency to `1`. That way you get a mutually exclusive lock.

[Professionally supported throat is now available](https://tidelift.com/subscription/pkg/npm-throat?utm_source=npm-throat&utm_medium=referral&utm_campaign=readme)

[![Build Status](https://img.shields.io/github/actions/workflow/status/ForbesLindesay/throat/test.yml?branch=master&style=for-the-badge)](https://github.com/ForbesLindesay/throat/actions/workflows/test.yml?query=branch%3Amaster)
[![Coveralls github branch](https://img.shields.io/coveralls/github/ForbesLindesay/throat/master?color=brightgreen&style=for-the-badge)](https://coveralls.io/github/ForbesLindesay/throat)
[![Rolling Versions](https://img.shields.io/badge/Rolling%20Versions-Enabled-brightgreen?style=for-the-badge)](https://rollingversions.com/ForbesLindesay/throat)
[![NPM version](https://img.shields.io/npm/v/throat?style=for-the-badge)](https://www.npmjs.com/package/throat)

## Installation

    npm install throat

## API

### throat(concurrency)

This returns a function that acts a bit like a lock (exactly as a lock if concurrency is 1).

Example, only 2 of the following functions will execute at any one time:

```js
const throat = require('throat')(2);

const resA = throat(async () => {
  /* async stuff... */
});
const resB = throat(async () => {
  /* async stuff... */
});
const resC = throat(async () => {
  /* async stuff... */
});
const resD = throat(async () => {
  /* async stuff... */
});
const resE = throat(async () => {
  /* async stuff... */
});
```

### throat(concurrency, worker)

This returns a function that is an exact copy of `worker` except that it will only execute up to `concurrency` times in parallel before further requests are queued:

```js
const throat = require('throat');

const input = ['fileA.txt', 'fileB.txt', 'fileC.txt', 'fileD.txt'];
const data = Promise.all(
  input.map(throat(2, (fileName) => readFile(fileName)))
);
```

Only 2 files will be read at a time, sometimes limiting parallelism in this way can improve scalability.

## Security contact information

To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure.

## License

MIT

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