fast-iterator
Fast execution of an array of functions with the same value as input that can be altered.
Last updated 9 years ago by delvedor .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install fast-iterator 
SYNC missed versions from official npm registry.

fast-iterator

js-standard-style Build Status

Fast execution of an array of functions with the same value as input that can be altered.

Install

npm i fast-iterator --save

Usage

const fast = require('fast-iterator')

fast(
  [fn1, fn2, fn3], // the array of functions to execute
  { context: true } // a custom context for every function
)(
  iterator.bind({ a: 'a', b: 'b' }), // an iterator function to pass custom parameters
  { hello: 'world' }, // the value to update
  done // the function to call once the work has been done
)

function fn1 (a, b, result, done) {
  console.log(a, b, result, this)
  done(null, { ciao: 'mondo' })
}

function fn2 (a, b, result, done) {
  console.log(a, b, result, this)
  done(null, { winter: 'is coming' })
}

async function fn3 (a, b, result) {
  console.log(a, b, result, this)
  return { winter: 'has come' }
}

function iterator (fn, result, done) {
  return fn(this.a, this.b, result, done)
}

function done (err, result) {
  console.log(err || result, this)
}

Output:

a b { hello: 'world' } { context: true }
a b { ciao: 'mondo' } { context: true }
a b { winter: 'is coming' } { context: true }
{ winter: 'has come' } { context: true }

If you need to release the internal Object holder for performances reasons, you can call the fourth parameter of the iterator: release.

function iterator (fn, result, done, release) {
  if (someCondition) return release()
  return fn(this.a, this.b, result, done)
}

Acknowledgements

This project is kindly sponsored by LetzDoIt.

License

Licensed under MIT.

Current Tags

  • 0.3.0                                ...           latest (9 years ago)

5 Versions

  • 0.3.0                                ...           9 years ago
  • 0.2.2                                ...           9 years ago
  • 0.2.1                                ...           9 years ago
  • 0.2.0                                ...           9 years ago
  • 0.1.0                                ...           9 years ago
Maintainers (1)
Downloads
Total 20
Today 0
This Week 0
This Month 11
Last Day 0
Last Week 1
Last Month 5
Dependencies (1)
Dev Dependencies (2)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE