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

enabling Transforms in exported module #31

Closed
codebling opened this issue Aug 28, 2016 · 2 comments
Closed

enabling Transforms in exported module #31

codebling opened this issue Aug 28, 2016 · 2 comments

Comments

@codebling
Copy link

I'm using the following code, which works great:

module.exports = {
  'bla': function() {
    var flow = asyncblock.getCurrentFlow();
    an.asyncCall('params', flow.add('a'));
    return flow.get('a');
  }
};

It might be nice to enable Transforms and use something like this:

module.exports = {
  'bla': function() {
    return an.asyncCall('params', flow.add('a')).sync();
  }
};

But since the exports are not wrapped in an asyncblock, the sync call doesn't get transformed and the result is TypeError: an.asyncCall(...).sync is not a function

Since this all lives in an Express app, my asyncblock gets launched elsewhere, but if I do explicitly wrap the exports in an asyncblock in order to force the transform, I get this:

/bla/node_modules/asyncblock/lib/flow_fiber.js:26
        this._fiber.run(task);
                    ^

TypeError: Cannot set property '_asyncblock_flow' of null
    at fiberContents (/bla/node_modules/asyncblock/lib/asyncblock.js:88:32)

Am I doing something wrong? Is there another way/is it possible to enable Transforms?

@scriby
Copy link
Owner

scriby commented Aug 28, 2016

Your best bet is like this:

module.exports = {
'bla': function() {
var flow = asyncblock.getCurrentFlow();
return flow.sync(an.asyncCall('params', flow.callback());
};
I'll think about adding something for transforms outside of an asyncblock context. The general way the library is intended to be used is more like this:

function bla(callback) {
ab(function() {
return an.asyncCall('params').sync():
}, callback);
};

So you would basically define an asyncblock every time you want to use it. That makes it compatible with the node callback pattern.

But you can do whichever you think is better for your style and use case, of course.

Thanks,

Chris

On Aug 28, 2016, at 2:24 PM, codebling notifications@github.com wrote:

module.exports = { 'bla': function() { var flow = asyncblock.getCurrentFlow(); an.asyncCall('params', flow.add('a')); return flow.get('a'); } };

@codebling
Copy link
Author

Thanks for the quick reply ! And ya, that's awesome, just wanted to check if there was a better way ! Thanks for the great library!!

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