# consec

> Consecutively iterate generator functions

Latest version **1.1.0** (published 2015-07-03) · MIT license · 0 weekly downloads

## Install

```sh
npm install consec
pnpm add consec
yarn add consec
bun add consec
```

## 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.0 |
| Published | 2015-07-03 |
| First published | 2015-04-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Sam Newman |
| Maintainers | sonewman |
| Keywords | generators, promises, koa, co, control-flow, async |

## Links

- npm: https://www.npmjs.com/package/consec
- Repository: https://github.com/sonewman/consec.js
- Homepage: https://github.com/sonewman/consec.js#readme
- Issues: https://github.com/sonewman/consec.js/issues
- npm.io page: https://npm.io/package/consec

## Alternatives

- [flatbuffers](https://npm.io/package/flatbuffers.md) — 6.0M weekly downloads
- [jwt-simple](https://npm.io/package/jwt-simple.md) — 259.5K weekly downloads
- [@exodus/patch-broken-hermes-typed-arrays](https://npm.io/package/@exodus/patch-broken-hermes-typed-arrays.md) — 28.5K weekly downloads
- [@native-to-anchor/buffer-layout](https://npm.io/package/@native-to-anchor/buffer-layout.md) — 12.2K weekly downloads
- [binary-parser-encoder](https://npm.io/package/binary-parser-encoder.md) — 5.3K weekly downloads

## Recent versions

- 1.1.0 (latest) — 2015-07-03
- 1.0.2 — 2015-04-30
- 1.0.1 — 2015-04-30
- 1.0.0 — 2015-04-30

## README

# consec
Wrap a bunch of async operations into one function and iterate each step `consecutively` seamlessly returning
a promise resolving with the end returned value. If an error is throw along the way or a yield promise
fails then the promise rejects allowing you to catch the error.

# Installation
```bash
$ npm install consec
```

# Usage
```javascript
var consec = require('consec')

consec(function * () {
  var res1 = yield Promise.resolve('abc')
  return yield Promise.resolve(res1)
}).then(function (res) {
  res // => 'abc'
})

// you can also yield regular values
consec(function * () {
  var res1 = yield 'abc'
  return yield res1
}).then(function (res) {
  res // => 'abc'
})

// you can pass in the function context and parameters
var ctx = {}
function * gen(a, b, c) {
  this // => ctx
  return yield ['a', 'b', 'c']
}

consec.call(ctx, gen, 'a', 'b', 'c')
.then(function (abc) {
  abc // => ['a', 'b', 'c']
})

// if an error is throwm then the chain ends there
var error = new Error()
consec(function * () {
  throw error
}).catch(function (err) {
  err // => error
})

//  if a promise is rejected then the chain ends there
var error = new Error()
consec(function * () {
  yield Promise.reject(error)

  // this is never reached
  return 'abc'
}).catch(function (err) {
  err // => error
})
  
// a generator can also be yielded
function * g() {
  return yield Promise.resolve('abc')
}
consec(function * () {
  var a = yield * g()
  t.equals(a, 'abc')
})

// finally you can even nest consec calls inside one another
function * g(abc) {
  return yield Promise.resolve(abc)
}

return consec(function * () {
  return yield consec(g, 'abc')
}).then(function (res) {
  res // => 'abc'
})
```

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