Home

Awesome

<p align="center"> <img src="./benz.png"> </p> <p align="center"> <a href="https://codeclimate.com/github/tunnckoCore/benz"> <img src="https://img.shields.io/codeclimate/github/tunnckoCore/benz.svg"> </a> <a href="https://github.com/feross/standard"> <img src="https://img.shields.io/badge/code%20style-standard-brightgreen.svg"> </a> <a href="https://travis-ci.org/tunnckoCore/benz"> <img src="https://img.shields.io/travis/tunnckoCore/benz.svg"> </a> <a href="https://coveralls.io/r/tunnckoCore/benz"> <img src="https://img.shields.io/coveralls/tunnckoCore/benz.svg"> </a> <a href="https://david-dm.org/tunnckoCore/benz"> <img src="https://img.shields.io/david/tunnckoCore/benz.svg"> </a> </p>

benz npmjs.com The MIT License

Compose your control flow with absolute elegance. Support async/await, callbacks, thunks, generators, promises, observables, child processes and streams. Can power applications that need to have plugins. Useful for creating task, test and bench runners. Built with backward compatibility and future stability in mind.

Install

npm i benz --save
npm test

Usage

For more use-cases see the tests

var benz = require('benz')

API

Benz

Create a new instance of Benz.

Example

var Benz = require('benz')
var benz = new Benz()

.compose

Used internally to create .parallel and .series methods.

Example

var fs = require('fs')
var benz = require('benz')
var series = benz().compose('series')

var done = series([
  function (fp, encoding, next) {
    fs.readFile(fp, encoding, next)
  },
  function (content, next) {
    var name = JSON.parse(content).name
    next(null, name)
  }
])

done('./package.json', 'utf8', function (err, res) {
  console.log(err) //=> null
  console.log(res)
  //=> ['{\n  "name": "benz",\n  "version": "0.4.0" ...', 'benz']
})

.series

Run fns (plugins stack) in series.

Example

var done = benz.series([
  function one (initial, next) {
    setTimeout(function () {
      console.log('second')
      next(null, initial + 555)
    }, Math.random() * 50)
  },
  function two (initial, next) {
    setTimeout(function () {
      console.log('third')
      next(null, initial + 333)
    }, Math.random() * 200)
  },
  function three (initial, next) {
    setTimeout(function () {
      console.log('first')
      next(null, initial + 111)
    }, 0)
  }
])

done(222, function (err, res) {
  //=> 'second'
  //=> 'third'
  //=> 'first'

  console.log(err, res)
  //=> [777, 555, 111]
})

.parallel

Run fns (plugins stack) in paralell and maintain order of the results.

Example

var done = benz.parallel([
  function one (initial, next) {
    setTimeout(function () {
      console.log('second')
      next(null, initial + 300)
    }, Math.random() * 50)
  },
  function two (initial, next) {
    setTimeout(function () {
      console.log('third')
      next(null, initial + 100)
    }, Math.random() * 200)
  },
  function three (initial, next) {
    setTimeout(function () {
      console.log('first')
      next(null, initial + 444)
    }, 0)
  }
])

done(100, function (err, res) {
  //=> 'first'
  //=> 'second'
  //=> 'third'

  console.log(err, res)
  //=> [400, 200, 544]
})

.run

Alias of .series and .parallel. By default will run the stack in series, otherwise in parallel, but only if parallel option is enabled.

Example

var fs = require('fs')
var done = benz.enable('onlylast').run([
  fs.readFile,
  function (content, next) {
    next(null, JSON.parse(content).name)
  }
])

done('./package.json', 'utf8', function (err, res) {
  console.log(err, res) //=> null 'benz'
})

Contributing

Pull requests and stars are always welcome. For bugs and feature requests, please create an issue.
But before doing anything, please read the CONTRIBUTING.md guidelines.

Charlike Make Reagent new message to charlike freenode #charlike

tunnckocore.tk keybase tunnckocore tunnckoCore npm tunnckoCore twitter tunnckoCore github