Using async / await inside async.auto chain leads to TypeError: callback is not a function
See original GitHub issueWhat version of async are you using? 2.6.1
Which environment did the issue occur in (Node version/browser version) 8.11.3
What did you do? Please include a minimal reproducible case illustrating the issue. Assuming fileObj is supplied from outside:
async.auto({
download: (downloadCB) => {
if (fileObj) {
fs.writeFile(__dirname + ‘fileNew.txt’, fileObj.content, 'base64', function (err) {
if (err){
return downloadCB(err);
}
return downloadCB(null , fileObj.generatedFileName); // works fine
});
} else {
let err = new Error('File not found');
return downloadCB(err);
}
},
collectData: ['download', async (results, collectCB) => {
console.log(typeof collectCB); // prints undefined
console.log(typeof results); // prints correct object
let res = await anHttpRequest();
if (res.response && res.response.statusCode == 200) {
return collectCB(null , 'fileCombined.txt'); // This is where the ISSUE happens
}
else if(res.response.statusCode >= 300) {
return collectCB(new Error('Request failed inside async-auto'));
}
}],
filterData: ['collectData', (results, filterCB) => {
doFilter(results.collectData, filterCB);
}],
})
What did you expect to happen? After collectData finishes execution, filterData should begin execution the param passed inside collectCB function
What was the actual result? TypeError: collectCB is not a function.
The same code executes well with version 2.0.1 but after upgrade to 2.6.1 it has stopped working and its critical for us. Any work arounds will also be appreciated.
Issue Analytics
- State:
- Created 5 years ago
- Comments:5
Top Results From Across the Web
Using async / await inside async.auto chain leads to TypeError
In this case, the async function will not be passed a final callback argument, and any thrown error will be used as the...
Read more >Async/await - The Modern JavaScript Tutorial
asynchronous code returns a value, but it wraps the value in a Promise, so that the caller can use it to specify the...
Read more >Using async/await - AWS SDK for JavaScript
You can use the async/await pattern in your calls to the AWS SDK for JavaScript. Most functions that take a callback do not...
Read more >How to use promises - Learn web development | MDN
To understand how to use promises in JavaScript. In the last article, we talked about the use of callbacks to implement asynchronous functions....
Read more >Async.js
Async accepts async functions wherever we accept a Node-style callback function. However, we do not pass them a callback, and instead use the...
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 FreeTop 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
Top GitHub Comments
We treat
async
functions differently – we do not pass them a callback. Instead, simplyreturn
a value (orthrow
an error).I’d like to re-write a lot of the examples in the docs to use more async/await, to highlight what you can do now.