0

I am using async waterfall like this

const profileRichness = () => {
    async.waterfall([
        getTargetUsers,
        filterUser,
        
    ], (err) => {
        if (err) errorlogger(uuid(), err, "email", "abc", "acc", "acd");
        else console.log('Done');
    });
}

Fn that I am calling

const getTargetUsers = (callback,condition) => {
    user.getUsers(condition, (err, result) => {
        if (err)
            callback(err);
        else {

            if (result.length)
                callback(null, result);
            else
                callback('No user found');
        }
    });
}

const filterUser = (users, callback) => {
    users = users.filter(user => {
        if (!user.age || user.profile < 80) return user;
        else return false;
    }).filter(user => user);
    callback(null,users);
}

Problem is whatever I am trying to pass in first function of waterfall it returns error that "callback is not a function" what is exactly going on

Saurabh
  • 1,592
  • 2
  • 14
  • 30
  • FWIW, here in 2021, I'd just use `async` functions and `await`, and if I had to use an old-fashioned callback-based API function I'd [wrap it in a promise](https://stackoverflow.com/questions/22519784/how-do-i-convert-an-existing-callback-api-to-promises). – T.J. Crowder Dec 19 '21 at 11:44
  • Is [this](https://www.npmjs.com/package/async-waterfall) the function you're using? From that documentation, it looks like the callback is always the *last* parameter, but your `getTargetUsers` is expecting something else after it. – T.J. Crowder Dec 19 '21 at 11:46
  • I think you should show how filterUser is defined – Tushar Shahi Dec 19 '21 at 11:47
  • Also note that `return user` inside a `filter` doesn't make sense; the callback for `filter` returns a *flag*. And the second `filter` after it is pointless (there won't be any falsy values in the array returned by the first one; if there were, the first `filter` would have thrown an error or weeded them out). That whole filter should just be `users = users.filter(user => !user.age || user.profile < 80);` – T.J. Crowder Dec 19 '21 at 11:55
  • I think this should help : https://stackoverflow.com/questions/40269584/async-callback-is-not-a-function – Tushar Shahi Dec 19 '21 at 11:56

0 Answers0