# promise-wip-throttler

> throttle promises

Latest version **0.2.1** (published 2017-11-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install promise-wip-throttler
pnpm add promise-wip-throttler
yarn add promise-wip-throttler
bun add promise-wip-throttler
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.1 |
| Published | 2017-11-20 |
| First published | 2017-10-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | d-dog@d-dog.se |
| Maintainers | daniel-lundin |
| Keywords | promise, throttler, wip |

## Links

- npm: https://www.npmjs.com/package/promise-wip-throttler
- Repository: https://github.com/daniel-lundin/promise-wip-throttler
- Homepage: https://github.com/daniel-lundin/promise-wip-throttler#readme
- Issues: https://github.com/daniel-lundin/promise-wip-throttler/issues
- npm.io page: https://npm.io/package/promise-wip-throttler

## Alternatives

- [adhdev](https://npm.io/package/adhdev.md) — 11.1K weekly downloads
- [react-slide-button](https://npm.io/package/react-slide-button.md) — 310 weekly downloads
- [better](https://npm.io/package/better.md) — 42 weekly downloads
- [react-native-swipe-image](https://npm.io/package/react-native-swipe-image.md) — 22 weekly downloads
- [nl.fokkezb.pulltorefresh](https://npm.io/package/nl.fokkezb.pulltorefresh.md) — 11 weekly downloads

## Recent versions

- 0.2.1 (latest) — 2017-11-20
- 0.1.1 — 2017-11-08
- 0.1.0 — 2017-11-05
- 0.0.3 — 2017-10-04
- 0.0.2 — 2017-10-04
- 0.0.1 — 2017-10-04

## README

# promise-wip-throttler
[![Build Status](https://travis-ci.org/daniel-lundin/promise-wip-throttler.svg?branch=master)](https://travis-ci.org/daniel-lundin/promise-wip-throttler)

Set a WIP(work in progress) limit for your promises.

`npm install promise-wip-throttler`

## Example use cases

 - Make sure to not overload an external service.
 - Limit the number of concurrent memory heavy and/or CPU intensive tasks.

## Usage

The following example creates a throttler that will only allow 2 `heavyOperation`s to run concurrently.
The third one will not be started until one of the first two resolves.

```js

import { createThrottler } from 'promise-wip-throttler';

const throttler = createThrottler(2);

throttler(() => heavyOperation());
throttler(() => heavyOperation());
throttler(() => heavyOperation());
throttler(() => heavyOperation());
throttler(() => heavyOperation());
throttler(() => heavyOperation());
throttler(() => heavyOperation());
```

## Decorator

The throttler is also available as a higher order function that can wraps the target function. The throttled function returns a promise that will resolve once the function has finished executing.

```js

import { throttled } from 'promise-wip-throttler';


function mySlowFunction() {
 // Heavy lifting, retuns a promise
}

const myThrottledSlowFunction = throttled(1)(mySlowFunction);

// Will only run one at a time
myThrottledSlowFunction().then(() => { console.log('I\'m done'); });
myThrottledSlowFunction().then(() => { console.log('I\'m done'); });
myThrottledSlowFunction().then(() => { console.log('I\'m done'); });
myThrottledSlowFunction().then(() => { console.log('I\'m done'); });
myThrottledSlowFunction().then(() => { console.log('I\'m done'); });
myThrottledSlowFunction().then(() => { console.log('I\'m done'); });

```

## License

MIT
 
Copyright Daniel Lundin 2017

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