# command-executor

> Simple Async Executor

Latest version **2.0.2** (published 2016-02-19) · ISC license · 0 weekly downloads

## Install

```sh
npm install command-executor
pnpm add command-executor
yarn add command-executor
bun add command-executor
```

## 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 | 2.0.2 |
| Published | 2016-02-19 |
| First published | 2016-02-19 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Viktor Somodi |
| Maintainers | sviktor |

## Links

- npm: https://www.npmjs.com/package/command-executor
- Repository: https://github.com/Valetudox/command-executor
- Homepage: https://github.com/Valetudox/command-executor#readme
- Issues: https://github.com/Valetudox/command-executor/issues
- npm.io page: https://npm.io/package/command-executor

## Dependencies (2)

- [co](https://npm.io/package/co.md) ^4.6.0
- [lodash](https://npm.io/package/lodash.md) ^4.5.0

## Recent versions

- 2.0.2 (latest) — 2016-02-19
- 2.0.1 — 2016-02-19
- 2.0.0 — 2016-02-19
- 1.0.0 — 2016-02-19

## README

# Async Executer [![Coverage Status](https://coveralls.io/repos/github/Valetudox/command-executor/badge.svg?branch=master)](https://coveralls.io/github/Valetudox/command-executor?branch=master)

Simple Async Executor

Install
---------

```bash
npm install --save command-executor
```
Setup
---------

```javascript
const { parallel, sequence } = require('command-executor');

```

Parallel
---------

```javascript
const result = yield parallel([
    () => sleep(50).then(() => '[X]'),
    () => Promise.reject(ex),
    () => Promise.resolve('[Y]')
]);
t.same(result, ['[X]', ex, '[Y]']);
```
Sequence
---------

```javascript
const ex = new Error('[ERR]');
const commands = [
    () => sleep(20).then(() => '[X]'),
    () => Promise.reject(ex),
    () => Promise.resolve('[Y]')
];
const result = yield parallel(commands);
t.same(result, ['[X]', ex]);
```

Combined
---------

```javascript
const ex = new Error('[First]');
const main1 = () => sequence([
  () => Promise.resolve('[X]'),
  () => Promise.reject(ex)
]);
const main2 = () => sequence([
  () => Promise.reject(ex),
  () => Promise.resolve('[Y]')
]);
const result = yield parallel([main1, main2]);
t.same(result, [['[X]', ex], [ex]]);
```

# Async Executer for tasks

Setup
---------

```javascript
const { parallel, sequence } = require('command-executor').tasks;
```

Parallel
---------

```javascript
const result = yield parallel([{
    id: 'Create Production',
    command: () => Promise.resolve('[X]')
}, {
    id: 'Create Stage',
    command: () => Promise.reject(new Error('[Y]'))
}]);

t.same(result, [{
    id: 'Create Production',
    result: '[X]',
    state: 'resolved'
}, {
    id: 'Create Stage',
    result: new Error('[Y]'),
    state: 'rejected'
}]);
```

Sequent
---------

```javascript
const result = yield sequence([{
    id: 'Create Production',
    command: () => Promise.reject(new Error('[X]')
}, {
    id: 'Create Stage',
    command: () => Promise.resolve('[Y]'))
}]);

t.same(result, [{
    id: 'Create Production',
    result: new Error('[X]'),
    state: 'rejected'
}, {
    id: 'Create Stage',
    result: undefined,
    state: 'skipped'
}]);
```

Combined
---------

```javascript
const result = yield parallel([{
    id: 'mainTask1',
    command: () => sequence([
        { id: 'task1', command: () => Promise.resolve('[X]') },
        { id: 'task2', command: () => parallel([
            { id: 'subtask1', command: () => Promise.resolve('[H]'),
            { id: 'subtask2', command: () => Promise.resolve('[G]')
        ]) }
    ])
  }, {
    id: 'mainTask2',
    command: () => sequence([
        { id: 'task3', command: () => Promise.reject(new Error('[V]')) },
        { id: 'task4', command: () => Promise.resolve('[Z]') }
    ])
  }]);
  
  t.same(result, [
      {
        id: 'mainTask1',
        result: [
          { id: 'task1', result: '[X]', state: 'resolved' },
          { 
            id: 'task2', 
            result: [
              { id: subtask1, result: '[H]', state: 'resolved' },
              { id: subtask2, result: '[G]', state: 'resolved' }
            ], 
            state: 'resolved'
          }
        ],
        state: 'resolved'
      },
      {
        id: 'mainTask2',
        result: [
          { id: 'task3', result: new Error('[V]'), state: 'rejected' },
          { id: 'task4', result: undefined, state: 'skipped' }
        ],
        state: 'resolved'
      }
    ]
  );
```

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