V
V
vetsmen2017-01-30 14:31:26
JavaScript
vetsmen, 2017-01-30 14:31:26

async node.js not working?

There is such a function

getBalance = function(id) {
    connection.query('SELECT balance FROM Users WHERE id = ?', id, function(error, result, fields) {
    	if(error)
    		return error;
        if(result[0]['balance'])
            return result[0]['balance'];
        return 0;
    });
};

I need to get the result from it using the async library, I do this:
var a = async.parallel(getBalance(123123), function(err, callback){
            if (err) throw err;
            return callback;
    });
    console.log(a);

I get underfind, what could be the problem?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
emp1re, 2017-01-30
@vetsmen

async.parallel([getBalance(123123)], function(err, result){
            if (err)   return next(err); //<- custom error handler
            // do result;
           console.log(result);
    });

[getBalance(123123)] or {name:getBalance(123123)}
var getBalance = (callback) => {
    connection.query('SELECT balance FROM Users WHERE id = ?', id, (error, result, fields) => {
    	if(error)
    	   return callback(error);
        if(result[0]['balance'])
            callback(null, result[0]['balance']);
  
    });
      callback(null, 0);
}
;

V
Vitaly, 2017-01-31
@vshvydky

don't you like native async await?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question