# max-in-flight

> Limits how many async operations (promises) will be started concurrently

Latest version **2.0.0** (published 2018-02-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install max-in-flight
pnpm add max-in-flight
yarn add max-in-flight
bun add max-in-flight
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2018-02-26 |
| First published | 2018-01-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 42.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | DavidC., david@dchere.com |
| Maintainers | dacz |

## Links

- npm: https://www.npmjs.com/package/max-in-flight
- Repository: https://github.com/dacz/max-in-flight
- Homepage: https://github.com/dacz/max-in-flight#readme
- Issues: https://github.com/dacz/max-in-flight/issues
- npm.io page: https://npm.io/package/max-in-flight

## Recent versions

- 2.0.0 (latest) — 2018-02-26
- 1.0.0 — 2018-01-10

## README

# Max In Flight

Limits max. async running operations.

[![current version](https://img.shields.io/npm/v/max-in-flight.svg?style=flat-square)](https://www.npmjs.com/package/max-in-flight)
[![travis.ci](https://img.shields.io/travis/dacz/max-in-flight.svg?style=flat-square)](https://travis-ci.org/dacz/max-in-flight)
[![codecov](https://codecov.io/gh/dacz/max-in-flight/branch/master/graph/badge.svg)](https://codecov.io/gh/dacz/max-in-flight)
[![Greenkeeper badge](https://badges.greenkeeper.io/dacz/max-in-flight.svg)](https://greenkeeper.io/)
[![license](https://img.shields.io/github/license/dacz/max-in-flight.svg)](https://github.com/dacz/max-in-flight/blob/master/LICENSE)


## Install

```
npm install max-in-flight
```


## Motivation:

I needed to call great amount of requests to http endpoint from different places of my server side app (graphql bridge with huge query running) and I needed to be sure that only XX requests will be in flight otherwise the server will go down.

There are other solutions when you have existing array of async functions to call and you need to limit their processing (starting).

This was not the case, I needed kind of FIFO queue for such calls, because the requests were initiated in multiple places of an app.

## How to use it:

```javascript
import maxInFlight from 'maxInFlight';
// limit number of max. concurrent async operation
const defer = maxInFlight(3).deferCall;
async function() {
  const result = await defer(
    fetch,
    'http://some.com', ... any other args for fetch ...);
}

// alternatively you can use it to defer fn and use this defered fn then
const deferFetch = maxInFlight(3).deferFn(fetch);
const result = await deferFetch('http://some.com', ...);
```

Error is propagated to the defer so operation may fail and will not take down other operations in flight or any submitted in the future.

## License - MIT

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