npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

fastfall

v1.5.1

Published

call your callbacks in a waterfall, at speed

Downloads

782,068

Readme

fastfall

npm version Build Status Coverage Status Dependency Status

call your callbacks in a waterfall, without overhead

Benchmark for doing 3 calls setImmediate 100 thousands times:

These benchmarks where taken via bench.js on node 4.2.2, on a MacBook Pro Retina 2014 (i7, 16GB of RAM).

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.

js-standard-style

Install

npm install fastfall --save

Usage

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([a, b, c], result)

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(new State('world'), [
  a, b, c,
], console.log)

function State (value) {
  this.value = value
}

function a (cb) {
  console.log(this.value)
  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')
}

Compile a waterfall

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)
})

API

fastfall([this], [functions])

Creates a fall, it can either be pre-filled with a this value and an array of functions.

If there is no list of functions, a not-compiled fall is returned, if there is a list of function a compiled fall is returned.

fall([this], functions, [done])

Calls the functions in a waterfall, forwarding the arguments from one to another. Calls done when it has finished.

fall(args..., [done])

Calls the compiled functions in a waterfall, forwarding the arguments from one to another. Additionally, a user can specify some arguments for the first function, too. Calls done when it has finished.

License

MIT