Callback is undefined on async/await function
See original GitHub issueNot sure this is a bug or not. It worked on my production environment right now (docker, node:7.7.0-alpine, async@2.1.5). Please guide me.
What version of async are you using? 2.3.0
Which environment did the issue occur in (Node version/browser version) 7.9.0
What did you do? Please include a minimal reproducable case illustrating issue.
const { eachSeries } = require('async')
eachSeries(
[1,2,3],
async (item, cb) => { // <----- it works if remove ```async```
console.log( 'item:', item )
console.log( 'cb:', typeof(cb) )
console.log()
cb()
},
err => {
console.log('err:', err)
}
)
What did you expect to happen?
item: 1
cb: function
item: 2
cb: function
item: 3
cb: function
err: null
What was the actual result?
item: 1
cb: undefined
err: TypeError: cb is not a function
Issue Analytics
- State:
- Created 6 years ago
- Reactions:4
- Comments:7
Top Results From Across the Web
JS async function returning undefined although calling it ...
query is taking a callback function, which implies it isn't returning a promise. You need to either: Find out how to make the...
Read more >AWS Lambda function handler in Node.js
The callback function takes two arguments: an Error and a response. When you call it, Lambda waits for the event loop to be...
Read more >JavaScript Promises and Async/Await: As Fast As Possible™
If no payload passed to these function, the payload is undefined. When resolve is called, then method (AKA handler) is called which executes...
Read more >How to rewrite a callback function in Promise form and async ...
It would be so great to be able to develop using modern JavaScript and start making use of the async/await functionality... If you...
Read more >async function - JavaScript - MDN Web Docs - Mozilla
The behavior of async / await is similar to combining generators and promises. Async functions always return a promise. If the return value...
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
Figured out that I have to use it this way:
Result:
You are correct – the
cb
is no longer passed toasync
functions. (Changed in 2.3.0)That final
Promise.resolve()
is not needed. Forasync
functions, the return value becomes the result.