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;
});
};
var a = async.parallel(getBalance(123123), function(err, callback){
if (err) throw err;
return callback;
});
console.log(a);
async.parallel([getBalance(123123)], function(err, result){
if (err) return next(err); //<- custom error handler
// do result;
console.log(result);
});
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);
}
;