Skip to content
Compose a queue of functions
JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
test
.gitignore
.npmignore
.travis.yml
Composer.js
LICENSE
README.md
package.json

README.md

Compo

Compose a queue of functions. The returns values of the previous function are passed as arguments to the next one.

Installation

npm install compo

Example

var Composer = require('compo');
var composer = new Composer();

composer.add(addOne);
composer.add(addOne);
composer.add(function (num) {
    console.log(num); // 3
});

composer.run(1);

function addOne(num, next) {
    next(num + 1);
}

API

composer.add(fn);

Add a function to the composer queue, if the composer has already run, the function will be automatically dequeued and executed, unless the previous function hasn't finished yet.

fn has a signature of fn(..args, next), where ...args is the returned values of previous function, and next is a callback function that should be called when fn is finished.

You can pass arguments to next(), which will be the returned values of the function. return values directly won't work.

composer.run(..args);

Run the composer, with ...args being passed to the first function in the queue as arguments.

Something went wrong with that request. Please try again.