# run-control

> Utils help control function run.

Latest version **1.0.2** (published 2018-04-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install run-control
pnpm add run-control
yarn add run-control
bun add run-control
```

## 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.0.2 |
| Published | 2018-04-27 |
| First published | 2017-11-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Unpacked size | 4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Author | zhaoyao91 |
| Maintainers | zhaoyao91 |
| Keywords | task, run, control |

## Links

- npm: https://www.npmjs.com/package/run-control
- Repository: https://github.com/zhaoyao91/run-control
- Homepage: https://github.com/zhaoyao91/run-control#readme
- Issues: https://github.com/zhaoyao91/run-control/issues
- npm.io page: https://npm.io/package/run-control

## Dependencies (3)

- [retry-times](https://npm.io/package/retry-times.md) ^2.0.0
- [promise-throttle](https://npm.io/package/promise-throttle.md) ^0.3.1
- [parallel-throttle](https://npm.io/package/parallel-throttle.md) ^1.0.0

## Alternatives

- [@mce/gif](https://npm.io/package/@mce/gif.md) — 2.6K weekly downloads
- [cleanse](https://npm.io/package/cleanse.md) — 173 weekly downloads
- [str](https://npm.io/package/str.md) — 127 weekly downloads
- [naming](https://npm.io/package/naming.md) — 95 weekly downloads
- [tap-telco-api](https://npm.io/package/tap-telco-api.md) — 19 weekly downloads

## Recent versions

- 1.0.2 (latest) — 2018-04-27
- 1.0.1 — 2017-12-25
- 1.0.0 — 2017-11-10

## README

# Run Control

> Utils help control function run.

## Deprecation

**This package is deprecated, consider using the following packages instead:**

- [retry-func](https://github.com/zhaoyao91/retry-func)
- [rate-limit-func](https://github.com/zhaoyao91/rate-limit-func)
- [runs-limit-func](https://github.com/zhaoyao91/runs-limit-func)

## Introduction

Say, you have an async function with only one argument: options, like [request-facebook](https://github.com/zhaoyao91/request-facebook), now
you can leverage this package to easily enhance that function with **retry**, **rate limit** and **parallel limit**.

## Installation

```
npm i run-control
``` 

## Usage

```ecmascript 6
const {compose, withDefaultOptions, withRetry, withRateLimit, withParallelLimit} = require('run-control')
const requestFacebook = require('request-facebook')

// all features are implemented as high order functions
// so you can just compose them
const myRequestFacebook = compose(
  // feed default options
  withDefaultOptions({accessToken: ...}),
  
  // retry if failed
  withRetry({times: 5}),
  
  // limit max task in parallel
  withParallelLimit(1000),
  
  // limit dispatched tasks per second
  withRateLimit(100),
)(requestFacebook)

// now you can call the enhanced function with all the features you added
for (let i = 0; i < 10000; i++) {
  myRequestFacebook({...}).then(...).catch(...)
}
```

## API

Type definitions:

- target: async func(options?) => any
- wrapper: func(target) => target

### compose

`func(...wrappers) => wrapper`

### withDefaultOptions

Provide default options.

`func(defaultOptions) => wrapper`

### withRetry

Retry some times if task failed.

`func({times, onRetry}) => wrapper`

See [retry-times](https://github.com/zhaoyao91/retry-times) for more about the available options.

### withRateLimit

Only dispatch limited tasks within a second.

`func(rate) => wrapper`

- rate: Number - max tasks to be run within a second.

### withParallelLimit

Only limited tasks can be run at a any moment.

`func(parallelLimit) => wrapper`

- parallelLimit: Number - max tasks in parallel

## License

MIT

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