# action-sequence

> Process an array of promises in order

Latest version **1.1.2** (published 2021-04-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install action-sequence
pnpm add action-sequence
yarn add action-sequence
bun add action-sequence
```

## 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.1.2 |
| Published | 2021-04-12 |
| First published | 2018-10-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 5.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Cam Tullos |
| Maintainers | jdillick, camdagr8 |
| Keywords | promise, sequence |

## Links

- npm: https://www.npmjs.com/package/action-sequence
- Repository: https://github.com/camdagr8/ActionSequence
- Homepage: https://github.com/camdagr8/ActionSequence#readme
- Issues: https://github.com/camdagr8/ActionSequence/issues
- npm.io page: https://npm.io/package/action-sequence

## Alternatives

- [promise-throttle](https://npm.io/package/promise-throttle.md) — 44.2K weekly downloads
- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads

## Recent versions

- 1.1.2 (latest) — 2021-04-12
- 1.1.1 — 2019-10-24
- 1.1.0 — 2019-10-24
- 1.0.9 — 2019-10-24
- 1.0.8 — 2019-10-23
- 1.0.7 — 2019-10-23
- 1.0.6 — 2019-08-30
- 1.0.5 — 2019-08-30
- 1.0.4 — 2019-01-23
- 1.0.3 — 2018-10-23
- 1.0.2 — 2018-10-23
- 1.0.1 — 2018-10-23
- 1.0.0 — 2018-10-23

## README

# ActionSequence

Having `Promise.all()` is great, but some times you just want to run through a list of Promises or functions in fixed order.

> ActionSequence works in both Node and browser environments.

# Usage

```javascript
const ActionSequence = require("action-sequence");

const options = { delay: 500 };
const actions = {
  action1: ({ action, delay }) =>
    new Promise(resolve => {
      setTimeout(() => {
        resolve(1);
      }, delay);
    }),
  action2: ({ action, delay }) =>
    new Promise(resolve => {
      setTimeout(() => {
        resolve(2);
      }, delay);
    }),
  action3: ({ action, delay }) =>
    new Promise(resolve => {
      setTimeout(() => {
        resolve(3);
      }, delay);
    }),
  action4: () => {
    return 4;
  },
  action5: ({ context, prevAction }) => {
    return context[prevAction] + 1;
  }
};

ActionSequence({ actions, options })
  .then(context => console.log(context))
  .catch(error => console.log(error));

/**
 * Returns:
{ action1: 1, action2: 2, action3: 3, action4: 4, action5: 5 };
*/
```

> _Pro tip:_ Since `ActionSequence` returns a `Promise`, it's possible to process multiple `ActionSequence` promises in another `ActionSequence`.

# Parameters

**actions** `{Object}` Contains `Functions`.

**options** `{Object}` Parameters passed to each action `Function`.

**context** `{Object}` If an action returns a value, it will be added to the context object making it possible to use the output of a previous action in the current action. If an action does not return a value, `true` will be set at the context value for that action.

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