caolan / async

Async utilities for node and the browser
http://caolan.github.io/async/
MIT License
28.18k stars 2.41k forks source link

TypeError: callback is not a function #1757

Closed vipulchaursiya closed 3 years ago

vipulchaursiya commented 3 years ago
 var async = require('async')
  async.each(allVideos , async function (video, callback){

   var deatils = await getYoutubeVideoInfo(video.youtubeId)
      if(deatils && deatils.channelId)
      { console.log("do something")}
      callback();
  }, (err)=>{
      console.log(err)
      console.log("all task done")
  })

So when I run this code I'm getting this error TypeError: callback is not a function at C:\Users-USER\github\beusalons\manijment-api\models\Video.js:57:5 at processTicksAndRejections (internal/process/task_queues.js:93:5) all task done

But all things are working fine why I'm getting this error always, for all methods of async js library

abobakrd commented 3 years ago

From the docs:

Using ES2017 async functions Async accepts async functions wherever we accept a Node-style callback function. However, we do not pass them a callback, and instead use the return value and handle any promise rejections or errors thrown.

async.mapLimit(files, 10, async file => { // <- no callback!
    const text = await util.promisify(fs.readFile)(dir + file, 'utf8')
    const body = JSON.parse(text) // <- a parse error here will be caught automatically
    if (!(await checkValidity(body))) {
        throw new Error(`${file} has invalid contents`) // <- this error will also be caught
    }
    return body // <- return a value!
}, (err, contents) => {
    if (err) throw err
    console.log(contents)
})

We can only detect native async functions, not transpiled versions (e.g. with Babel). Otherwise, you can wrap async functions in async.asyncify().