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

Async auto pass in data from dependency #952

Closed
mlovrovich opened this issue Nov 4, 2015 · 1 comment
Closed

Async auto pass in data from dependency #952

mlovrovich opened this issue Nov 4, 2015 · 1 comment

Comments

@mlovrovich
Copy link

It would be nice if there was a way to pass in results from a dependency directly into the function.
So instead of doing this:

async.auto({
    a: testFunction,
    b: ['a', function(callback, results){
        testFunction2(results.a, callback);
    }]
})

We could do something like,

async.auto({
    a: testFunction,
    b: ['a', async.apply(testFunction2, <resultsOfA>)]
})
@aearly
Copy link
Collaborator

aearly commented Nov 4, 2015

#608 is a proposal for a different flavor of auto. I dont really like it because it relies on Function.toString() and won't play nice with minifiers.

I've also played around with code that builds the auto object from a list of steps, e.g.

[
  {
    task: function taskName(arg1, arg2, cb) {...},
    dependencies: ["arg1", "arg2"]
  },
  {
    task: function arg1 (cb) { cb(null, foo); }
  }
  //...
]

I've also played around with a couple higher-order functions that manipulate the argument order (from my experimental acomb library):

async.auto({
  taskName: ["arg1", "arg2", acomb.flip(acomb.spreadArgs(function (arg1, arg2, cb) {
    //...
  }, "arg1", "arg2")]
})

The main problem is you can't bind functions to future values, because they don't exist yet. Also, you always seem to have to explicitly specify the dependencies as strings. But one thing you can do is use function combinators that manipulate the arguments so that functions fit better into auto. It's a balance between usability and practicality and what is actually possible.

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

No branches or pull requests

2 participants