0.0.6 • Published 9 years ago

stack-queue v0.0.6

Weekly downloads
3
License
GPL v3
Repository
github
Last release
9 years ago

stack-queue

Test Status Dependency Status

Execution stacks compatible with promises

Installation

npm install --save stack-queue

Usage

Have you ever used express or connect?

If so, you should know how they share they stack with function ( req, res, next ).

This module allows you to apply a nextable queue method in any circunstance, and compatible with promises!

Lets see some examples:

connect Example

This is how you would implement a connect-like example:

var http = require( 'http' ),
    Stack = require( 'stack-queue' );

var stack = new Stack(),
    server = http.createServer( stack.dispatch.bind( stack ) ).listen( 80 );

// Now you should be able to stack things on request
stack.queue( function ( req, res, next ) {
    req.foo = 'bar';

    next();
});

// You can even chain stack.queue calls
stack
    .queue(function ( req, res ) {
        res.statusCode = 200;

        return somePromisedMethod();
    })
    .queue(function ( req, res, next ) {
        res.write( 'hey' );

        next();
    });

// Or provide an array with functions
stack.queue([
    function () { return true; },
    function () { throw new Error("WOW"); }
]);

Do you have more examples?

Please Pull Request them! :)