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.

Using async / await inside async.auto chain leads to TypeError: callback is not a function

See original GitHub issue

What 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:closed
  • Created 5 years ago
  • Comments:5

github_iconTop GitHub Comments

5reactions
aearlycommented, Sep 25, 2018

We treat async functions differently – we do not pass them a callback. Instead, simply return a value (or throw an error).

1reaction
aearlycommented, Nov 17, 2018

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.

Read more comments on GitHub >

github_iconTop 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 >

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