Compose a queue of functions

npm install compo
2 downloads in the last week
4 downloads in the last month


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


npm install compo


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

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

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



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.;

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

npm loves you