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.

Fix callback argument order in async.auto

See original GitHub issue

We should standardize the signature of async functions used in async.auto. Rather than always having the callback first, and the optional results object second, we should always make the callback the last argument.

We could also include a flip function that swaps the 2 arguments, to ease migration. (Or just instruct people to _.rearg(asyncFn, 1, 0)).

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:6

github_iconTop GitHub Comments

2reactions
aearlycommented, Mar 31, 2016

A config flag won’t work well – say all your functions expect the args flipped, but another node module expects the args un-flipped. If Async is de-duped to the same module, that config would conflict.

Wrapping all your dependent auto tasks with _.flip is probably the best way to migrate, until you can fix the callback ordering.

We didn’t just arbitrarily make this change for the sake of standardization – we made it so other higher-order functions would work properly. (e.g. directly passing the result of asyncify or timeout as an auto task function).

1reaction
sffccommented, Dec 30, 2017

I think the consistency in 2.x is nice, but I agree that there are advantages to having the callback first. It’s probably not worth changing at this point, but always having the callback first across the entire library, like the error argument, may have been a better design.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Callbacks & Higher-Order Functions in Javascript - Topcoder
A callback function is a function passed into another function as an argument, which is then invoked inside the outer function to complete...
Read more >
async callback for loop response out of order - Stack Overflow
The best way (for me), it's to use the async library. ... async.each is asynchronous, so at the end, the order will be...
Read more >
Node.js Async Best Practices & Avoiding the Callback Hell
This post covers what tools and techniques you have at your disposal when handling Node.js asynchronous operations. Learn how to avoid the ...
Read more >
async - Documentation - GitHub Pages
A callback which is called after all the iteratee functions have finished, or an error occurs. Results is an array containing the concatenated...
Read more >
Mastering Control Flow: Promises and Callbacks to Async and ...
If you haven't already guessed, this post will walk you through all things promises, callbacks, and JavaScript's newest flow control method, ...
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