creationix/step

Step is broken for use with Express.js!

eliaskg opened this issue · 1 comments

Hi,

I started to create an app with the most popular node web framework Express.js and I discovered that Step might be broken if you want to use it inside of Express.

For me it seems that res.send() is causing Step to "step forward" which is a bad, bad thing. Look at the following example app:

var express = require("express");
var step    = require("step");

var app = express.createServer();

app.get("/", function(req, res)
{
    step(
        function one()
        {
            console.log("one");

            if (true)
                return res.send("one");

            this();
        },
        function two()
        {
            console.log("two");

            res.send("two");
        }
    );
});

app.listen(8080, function() {
    console.log("App is running on port 8080");
});

If you run this example and go in your browser to http://localhost:8080 this is what you get:

As you can see in the code, the output "two" actually never should be happen because the first function inside of step should always return.

IMHO this is a really crucial bug because it makes Step (which is awesome by the way) almost unusable for most node projects.

It's not that res.send() is doing anything special, it's that you're forwarding it's return value to step. Return values are significant in the current version step. If you instead do res.send("one");return; you won't see this behaviour.

Also I'm considering removing this feature from Step. Please comment on this gist if you have input: https://gist.github.com/1524578