# call-limit

> Limit the number of simultaneous calls to an async function

Latest version **1.1.1** (published 2019-06-03) · ISC license · 0 weekly downloads

## Install

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

## 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 | 1.1.1 |
| Published | 2019-06-03 |
| First published | 2015-07-20 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 7.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 24 |
| Author | Rebecca Turner |
| Maintainers | iarna |

## Links

- npm: https://www.npmjs.com/package/call-limit
- Repository: https://github.com/iarna/call-limit
- Homepage: https://npmjs.com/packages/call-limit
- Issues: https://github.com/iarna/call-limit/issues
- npm.io page: https://npm.io/package/call-limit

## Recent versions

- 1.1.1 (latest) — 2019-06-03
- 1.1.0 — 2017-03-07
- 1.0.3 — 2015-09-18
- 1.0.2 — 2015-09-17
- 1.0.1 — 2015-07-21
- 1.0.0 — 2015-07-20

## README

call-limit
----------

Limit the number of simultaneous executions of a async function.

```javascript
const fs = require('fs')
const limit = require('call-limit')
const limitedStat = limit(fs.stat, 5)
```

Or with promise returning functions:

```javascript
const fs = Bluebird.promisifyAll(require('fs'))
const limit = require('call-limit')
const limitedStat = limit.promise(fs.statAsync, 5)
```

### USAGE:

Given that:

```javascript
const limit = require('call-limit')
```

### limit(func, maxRunning) → limitedFunc

The returned function will execute up to maxRunning calls of `func` at once. 
Beyond that they get queued and called when the previous call completes.

`func` must accept a callback as the final argument and must call it when
it completes, or `call-limit` won't know to dequeue the next thing to run.

By contrast, callers to `limitedFunc` do NOT have to pass in a callback, but
if they do they'll be called when `func` calls its callback.

### limit.promise(func, maxRunning) → limitedFunc

The returned function will execute up to maxRunning calls of `func` at once.
Beyond that they get queued and called when the previous call completes.

`func` must return a promise.

`limitedFunc` will return a promise that resolves with the promise returned
from the call to `func`.

### limit.method(class, methodName, maxRunning)

This is sugar for:

```javascript
class.prototype.methodName = limit(class.prototype.methodName, maxRunning)
```

### limit.method(object, methodName, maxRunning)

This is sugar for:

```javascript
object.methodName = limit(object.methodName, maxRunning)
```

For example `limit.promise.method(fs, 'stat', 5)` is the same as
`fs.stat = limit.promise(fs.stat, 5)`.

### limit.promise.method(class, methodName, maxRunning)

This is sugar for:

```javascript
class.prototype.methodName = limit.promise(class.prototype.methodName, maxRunning)
```

### limit.promise.method(object, methodName, maxRunning)

This is sugar for:

```javascript
object.methodName = limit.promise(object.methodName, maxRunning)
```

For example `limit.promise.method(fs, 'statAsync', 5)` is the same as
`fs.statAsync = limit.promise(fs.statAsync, 5)`.

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