call your callbacks in a waterfall, without overhead
Benchmark for doing 3 calls setImmediate
100 thousands times:
- non-reusable setImmediate: 553ms
- async.waterfall: 1718ms
- run-waterfall: 1321ms
- insync.wasterfall: 2044ms
- neo-async.wasterfall: 600ms
fastfall
: 585msfastfall
compiled: 603ms
These benchmarks where taken via bench.js
on iojs 2.2.1, on a MacBook
Pro Retina 2014, on battery, on a plane to London.
If you need zero-overhead series function call, check out fastseries, for parallel calls check out fastparallel, and for a fast work queue use fastq.
npm install fastfall --save
var fall = require('fastfall')()
fall([
function a (cb) {
console.log('called a')
cb(null, 'a')
},
function b (a, cb) {
console.log('called b with:', a)
cb(null, 'a', 'b')
},
function c (a, b, cb) {
console.log('called c with:', a, b)
cb(null, 'a', 'b', 'c')
}], function result (err, a, b, c) {
console.log('result arguments', arguments)
})
You can also set this
when you create a fall:
var that = { hello: 'world' }
var fall = require('fastfall')(that)
fall([
function a (cb) {
console.log(this)
console.log('called a')
cb(null, 'a')
},
function b (a, cb) {
console.log('called b with:', a)
cb(null, 'a', 'b')
},
function c (a, b, cb) {
console.log('called c with:', a, b)
cb(null, 'a', 'b', 'c')
}], function result (err, a, b, c) {
console.log('result arguments', arguments)
})
You can also set this
when you run a task:
var that = { hello: 'world' }
var fall = require('fastfall')()
fall(that, [
function a (cb) {
console.log(this)
console.log('called a')
cb(null, 'a')
},
function b (a, cb) {
console.log('called b with:', a)
cb(null, 'a', 'b')
},
function c (a, b, cb) {
console.log('called c with:', a, b)
cb(null, 'a', 'b', 'c')
}], function result (err, a, b, c) {
console.log('result arguments', arguments)
})
var fall = require('fastfall')([
function a (arg, cb) {
console.log('called a')
cb(null, arg)
},
function b (a, cb) {
console.log('called b with:', a)
cb(null, 'a', 'b')
},
function c (a, b, cb) {
console.log('called c with:', a, b)
cb(null, 'a', 'b', 'c')
}])
// a compiled fall supports arguments too!
fall(42, function result (err, a, b, c) {
console.log('result arguments', arguments)
})
You can set this
by doing:
var that = { hello: 'world' }
var fall = require('fastfall')(that, [
function a (arg, cb) {
console.log('this is', this)
console.log('called a')
cb(null, arg)
},
function b (a, cb) {
console.log('called b with:', a)
cb(null, 'a', 'b')
},
function c (a, b, cb) {
console.log('called c with:', a, b)
cb(null, 'a', 'b', 'c')
}])
// a compiled fall supports arguments too!
fall(42, function result (err, a, b, c) {
console.log('result arguments', arguments)
})
or you can simply attach it to an object:
var that = { hello: 'world' }
that.doSomething = require('fastfall')([
function a (arg, cb) {
console.log('this is', this)
console.log('called a')
cb(null, arg)
},
function b (a, cb) {
console.log('called b with:', a)
cb(null, 'a', 'b')
},
function c (a, b, cb) {
console.log('called c with:', a, b)
cb(null, 'a', 'b', 'c')
}])
// a compiled fall supports arguments too!
that.doSomething(42, function result (err, a, b, c) {
console.log('this is', this)
console.log('result arguments', arguments)
})
ISC