question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Ambiguity when async.auto provides an array

See original GitHub issue

When step A in an async.auto calls back with more than two arguments, a subsequent step B is shown an array as the result of step A. As far as I can tell, there is no way to distinguish (1) step A calling back in the usual way with an array, and (2) step A calling back with more than two arguments.

For example:

async.auto(
  {
    "stepA": function(cb) {
      cb(null, 1, 2);
    },
    "stepB": [
      "stepA",
      function(cb, result) {
        console.log(result.stepA); // [1, 2]
      }
    ]
  }
);
async.auto(
  {
    "stepA": function(cb) {
      cb(null, [1, 2]);
    },
    "stepB": [
      "stepA",
      function(cb, result) {
        console.log(result.stepA); // [1, 2]
      }
    ]
  }
);

If your auto step normally calls back with an array, but the oddball third argument is optional, I’m not sure there’s a robust way to tell if the third argument is present.

It does seem natural for auto to deal with more than one argument by providing an array, but maybe it should do something to resolve this ambiguity. For example, it could tag the array with a special property.

I realize that 2.0 has some changes to auto but, as far as I could tell, this particular issue is still present.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
CodeMan99commented, Sep 8, 2016

I published this on npm as callpack. The download numbers suggest that it has at least 10 users over the past two weeks.

0reactions
aearlycommented, Apr 1, 2017

I think we can rely on newer language features to smooth this over:

async.auto({
  task1: (cb) => {
    cb(null, 1, 2);
  },
  task2: ['task1', (results, cb) => {
    let [a, b] = results.task1;
    //....
  }]
}, done);
Read more comments on GitHub >

github_iconTop Results From Across the Web

ValueError: The truth value of an array with more than one ...
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all() when using cupy array ·...
Read more >
JavaScript: Promises and Why Async/Await Wins the Battle
What I find most fascinating about Async/Await is that it is built on top of Promises (non-blocking, etc.), yet allows for code to...
Read more >
async - Documentation - GitHub Pages
Async is a utility module which provides straight-forward, ... A function to apply to each item in coll , which should use an...
Read more >
Referencing async values with dynamically generated test ...
The value from the async Function needs to be passed to the test generator Function. Illustration that doesn't work: var testArray = function( ......
Read more >
ES2018: asynchronous iteration - 2ality
Operations are missing: Sync iterables can be converted to Arrays via the spread operator and accessed via Array destructuring. There are no ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found