# concurrency-runner

> Concurrency task runner

Latest version **0.0.4** (published 2019-09-24) · ISC license · 0 weekly downloads

## Install

```sh
npm install concurrency-runner
pnpm add concurrency-runner
yarn add concurrency-runner
bun add concurrency-runner
```

## Health

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

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.4 |
| Published | 2019-09-24 |
| First published | 2019-09-23 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 14.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Anatolii Domaratskyi |
| Maintainers | aplusd |
| Keywords | concurrency, generators, javascript |

## Links

- npm: https://www.npmjs.com/package/concurrency-runner
- Homepage: https://github.com/pretender91/concurrency-runner
- npm.io page: https://npm.io/package/concurrency-runner

## Recent versions

- 0.0.4 (latest) — 2019-09-24
- 0.0.3 — 2019-09-24
- 0.0.2 — 2019-09-23
- 0.0.1 — 2019-09-23

## README

# concurrency-runner

Concurrency primitives for js based on idies from [`ember-concurrency`](https://github.com/machty/ember-concurrency). It's not a production ready and created for test purpose.

## Installation

`concurrency-runner` is a not minified javascript es module lib. You can install it via:

    npm install concurrenct-runner

## Example of usage

```javascript
import {
  TaskScheduler,
  STRATEGIES,
  Task,
  deley
} from 'concurrency-runner';

const taskScheduler = new TaskScheduler(
  STRATEGIES.RESTARTABLE
);

/**
 * Task is generator
 */

const task = new Task(function*() {
  yield delay(1000);
  return 'resolved';
});

task.on('resolve', resolvedValue => {
  console.log(`resolved with: ${resolvedValue}`);
});
task.on('reject', rejectReason => {
  console.log(`rejected with: ${rejectReason}`);
});
task.on('cancel', cancelReason => {
  console.log(`cancelled with: ${cancelReason}`);
});

taskScheduler.execute(task);

taskSceduler.cancellAll();
```

There are several strategies:

- `STRATEGIES.DEFAULT` - all tasks is running as they executed.
- `STRATEGIES.RESTARTABLE` - ensures that only one instance of a task is running by canceling any currently-running tasks and starting a new task instance immediately
- `STRATEGIES.ENQUEUE` - ensures that only one instance of a task is running by maintaining a queue of pending tasks and running them sequentially.
- `STRATEGIES.DROP` - drops tasks that are exectuted while another is already running.
- `STRATEGIES.KEEP_LATEST` - will drop all but the most recent intermediate .execute(), which is enqueued to run later.

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