Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

skipping steps #35

Open
vpetrov opened this issue Jul 20, 2012 · 2 comments
Open

skipping steps #35

vpetrov opened this issue Jul 20, 2012 · 2 comments

Comments

@vpetrov
Copy link

vpetrov commented Jul 20, 2012

Is it possible to implement conditional control flow? I would like to skip over a few steps.
Something along these lines:

step(
        function f1() { find('foo',this); },
        function f2(err,foo) { if (foo) f4(foo); else return null; },
        function f3(err) { create('foo',this); },
        function f4(err,foo) { print(foo); }
);

If not, what is the best way to implement the code above?

@xavi-
Copy link
Contributor

xavi- commented Aug 15, 2012

Here's the easiest way I can think of:

step(
    function f1() { find('foo',this); },
    function f2(err,foo) {
        if (!foo) { // if there's no foo, create it
            create('foo', this)
        } else { // Otherwise this step is a no-op
            return foo; // Synchronously passed `foo` to the next step
        }
    },
    function f3(err,foo) { print(foo); }
);

That said, there's been some discussions on how to make this use case a bit more readable as well as some libraries that implement the ideas discussed:

@ppbntl19
Copy link

Call a function outside of step to output final data..

ie,

step (
function one(){
if ( error or validaation error) )  return  response(res, req, error)
//code
},
function two(){
//code
}.
function three(){
//code
}
)
function response(res, req, error) {
//Code
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants