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

Idea #3

Closed
alanhoff opened this issue Dec 24, 2011 · 2 comments
Closed

Idea #3

alanhoff opened this issue Dec 24, 2011 · 2 comments

Comments

@alanhoff
Copy link

What if I could pass informations to doneAdding() and add()?

I mean this:

asynchronous(function(){
var doc = {foo : bar};
flow.doneAdding(doc);
});

console.log(flow.forceWait()); // Output {foo : bar}

Thanks for your last modifications and good holly days for you!

@scriby
Copy link
Owner

scriby commented Dec 24, 2011

Thanks for the suggestion.

I'm not sure I can implement it exactly as you suggested, as forceWait returns the args passed to the callback from the async function.

var asyncTask = function(callback) {
    callback(null, 'data goes here');
};

asyncblock(function(flow){
    process.nextTick(function(){
        asyncTask(flow.add());

        flow.doneAdding();
    });
    console.log(flow.forceWait()); //Prints "data goes here"
});

If I wanted to store some information for later on, I could do it just by declaring a variable:

asyncblock(function(flow){
    var state;    

    process.nextTick(function(){
        asyncTask(flow.add());
        state = 'something';

        flow.doneAdding();
    });

    console.log(flow.forceWait()); //Prints "data goes here"
    console.log(state); //Prints "something"
});

I'm wondering if something like that addresses your request, or if you need something I'm not seeing.

I could add something like flow.setState(key, data) and flow.getState(key, data), but it seems like you can do it yourself by declaring your own variable.

Thanks,

Chris

@scriby
Copy link
Owner

scriby commented Jan 5, 2012

I'm going to close this for now. Feel free to re-open if needed.

@scriby scriby closed this as completed Jan 5, 2012
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

2 participants