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

invoke

v0.1.2

Published

Simple flow control library for chaining async functions

Downloads

1,348

Readme

invoke.js

invoke is a dead simple asynchronous flow control micro-library for node.js. Sequential (.then) and parallel (.and) async functions can be chained into simple steps:

invoke(function (data, callback) {
  // I'm an async function!
}).and(function (data, callback) {
  // I am too! I execute in parallel with the first function.
}).then(function (data, callback) {
  // I run after both of the parallel functions have called back. Their results
  // are passed to me as an array via the data arg.
}).rescue(function (err) {
  // I'll be invoked if any functions in the call chain call back with an error.
}).end(initialData, function (data) {
 // Calling .end initiates invocation of the set of chained steps. The final result
 // is passed to this callback.
});

Why?

Because I can.

This library is an experiment in flow control, chained APIs, and minimal JS syntax (yes, I skipped all those semi-colons on purpose).

Usage

invoke can be installed via npm:

npm install invoke

The API is exposed as a single function that generates a chainable Invocable object.

var invoke = require('invoke');

invoke(function (data, callback) {
  somethingAsync(function (err, results) {
    callback(err, results);
  });
}).then(function (data, callback) {
  // and so forth

Chainable methods on an Invocable:

then(func)

Adds a function as a sequential step. This function will not be invoked until all previous steps have called back, and later steps will not be invoked until this function calls back.

func is invoked with:

  • data - The result of the previous step. This is an arbitrary value if the previous step was sequential, or an array of arbitrary values if the previous step was parallel.
  • callback(err, results) - Function to be invoked once with either an error or the results of this step.

and(func)

Adds a function as a parallel step. This function will not be invoked in parallel with any other functions chained with .and immediately before or immediately after this .and call.

func is invoked with:

  • data - The result of the previous step. This is an arbitrary value if the previous step was sequential, or an array of arbitrary values if the previous step was parallel.
  • callback(err, results) - Function to be invoked once with either an error or the results of this step.

rescue(func)

Adds an error handler. This function will be invoked once if any function in the call chain calls back with an error.

func is invoked with

  • err - The error.

end(initialValue, callback)

Adds a final callback and initiates invocation of the function steps defined in the chain. initialValue is the initial value passed as the first argument into the first function step.

callback is invoked with

  • data - The result of the previous (final) step. This is an arbitrary value if the previous step was sequential, or an array of arbitrary values if the previous step was parallel.

License

invoke.js is MIT licensed. See LICENSE.