Fix callback argument order in async.auto
See original GitHub issueWe 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:
- Created 8 years ago
- Comments:6
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
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
ortimeout
as anauto
task function).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.